tracks lexicons and how many times they appeared on the jetstream
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(server): sort on major compact

dusk 29914c94 bf7842d0

+17 -10
+11 -2
server/src/db/handle.rs
··· 91 91 self.eps.observe(); 92 92 } 93 93 94 - pub fn compact(&self, compact_to: usize, range: impl RangeBounds<u64>) -> AppResult<()> { 94 + pub fn compact( 95 + &self, 96 + compact_to: usize, 97 + range: impl RangeBounds<u64>, 98 + sort: bool, 99 + ) -> AppResult<()> { 95 100 let start_limit = match range.start_bound().cloned() { 96 101 Bound::Included(start) => start, 97 102 Bound::Excluded(start) => start.saturating_add(1), ··· 117 122 118 123 let start_blocks_size = blocks_to_compact.len(); 119 124 let keys_to_delete = blocks_to_compact.iter().map(|(key, _)| key); 120 - let all_items = 125 + let mut all_items = 121 126 blocks_to_compact 122 127 .iter() 123 128 .try_fold(Vec::new(), |mut acc, (key, value)| { ··· 128 133 acc.append(&mut items); 129 134 AppResult::Ok(acc) 130 135 })?; 136 + 137 + if sort { 138 + all_items.sort_unstable_by_key(|e| e.timestamp); 139 + } 131 140 132 141 let new_blocks = all_items 133 142 .into_iter()
+5 -3
server/src/db/mod.rs
··· 207 207 nsid: impl AsRef<str>, 208 208 max_count: usize, 209 209 range: impl RangeBounds<u64>, 210 + sort: bool, 210 211 ) -> AppResult<()> { 211 212 let Some(handle) = self.get_handle(nsid) else { 212 213 return Ok(()); 213 214 }; 214 - handle.compact(max_count, range) 215 + handle.compact(max_count, range, sort) 215 216 } 216 217 217 218 pub fn compact_all( 218 219 &self, 219 220 max_count: usize, 220 221 range: impl RangeBounds<u64> + Clone, 222 + sort: bool, 221 223 ) -> AppResult<()> { 222 224 for nsid in self.get_nsids() { 223 - self.compact(nsid, max_count, range.clone())?; 225 + self.compact(nsid, max_count, range.clone(), sort)?; 224 226 } 225 227 Ok(()) 226 228 } 227 229 228 230 pub fn major_compact(&self) -> AppResult<()> { 229 - self.compact_all(self.max_block_size, ..)?; 231 + self.compact_all(self.max_block_size, .., true)?; 230 232 let _guard = scc::ebr::Guard::new(); 231 233 for (_, handle) in self.hits.iter(&_guard) { 232 234 handle.deref().major_compact()?;
+1 -1
server/src/main.rs
··· 155 155 }, 156 156 "running compaction...", 157 157 ); 158 - match db.compact_all(db.max_block_size, range) { 158 + match db.compact_all(db.max_block_size, range, false) { 159 159 Ok(_) => (), 160 160 Err(e) => tracing::error!("failed to compact db: {}", e), 161 161 }
-4
server/src/utils.rs
··· 290 290 } 291 291 } 292 292 293 - pub fn ago(duration: Duration) -> Self { 294 - Self::new(duration, TimeDirection::Backwards) 295 - } 296 - 297 293 pub fn from_now(duration: Duration) -> Self { 298 294 let cur = get_time(); 299 295 if duration > cur {