Get reverse history log from a view. Returns entries in reverse order (newest to oldest), starting from either the most recent change or a specified sequence number. # Arguments `txn` - Read transaction `view` - View to query `options` - Query options (from_sequence is the upper bound) # Returns A vector of history entries in reverse order. # Note This function collects entries into a vecto
(
txn: &T,
view: &ViewState,
options: &HistoryOptions,
)
| 170 | /// as the underlying iterator only supports forward iteration. |
| 171 | /// For large histories, consider using `log()` with pagination. |
| 172 | pub fn reverse_log<T: ViewTxnT>( |
| 173 | txn: &T, |
| 174 | view: &ViewState, |
| 175 | options: &HistoryOptions, |
| 176 | ) -> HistoryResult<Vec<HistoryEntry>> { |
| 177 | // Determine the range to query |
| 178 | let end_seq = if options.from_sequence > 0 { |
| 179 | options.from_sequence |
| 180 | } else { |
| 181 | view.change_count |
| 182 | }; |
| 183 | |
| 184 | let start_seq = if let Some(limit) = options.limit { |
| 185 | end_seq.saturating_sub(limit as u64) |
| 186 | } else { |
| 187 | 0 |
| 188 | }; |
| 189 | |
| 190 | // Collect forward and reverse |
| 191 | let forward_options = HistoryOptions { |
| 192 | from_sequence: start_seq, |
| 193 | limit: options.limit, |
| 194 | load_headers: options.load_headers, |
| 195 | view: options.view.clone(), |
| 196 | tagged_only: options.tagged_only, |
| 197 | include_inherited: options.include_inherited, |
| 198 | }; |
| 199 | |
| 200 | let iter = log(txn, view, &forward_options)?; |
| 201 | let mut entries: Vec<HistoryEntry> = iter.filter_map(|r| r.ok()).collect(); |
| 202 | entries.reverse(); |
| 203 | |
| 204 | Ok(entries) |
| 205 | } |
| 206 | |
| 207 | /// Get a summary of the view's history. |
| 208 | /// |
no test coverage detected