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.

refactor(server): use either instead of boxed iter

dusk 925dbc95 7cd979b3

+9 -11
+9 -11
server/src/db/mod.rs
··· 10 10 }; 11 11 12 12 use fjall::{Config, Keyspace, Partition, PartitionCreateOptions, Slice}; 13 - use itertools::Itertools; 13 + use itertools::{Either, Itertools}; 14 14 use ordered_varint::Variable; 15 15 use rkyv::{Archive, Deserialize, Serialize, rancor::Error}; 16 16 use smol_str::SmolStr; ··· 147 147 Ok(written) 148 148 } 149 149 } 150 - 151 - type BoxedIter<T> = Box<dyn Iterator<Item = T>>; 152 150 153 151 // counts is nsid -> NsidCounts 154 152 // hits is tree per nsid: varint start time + varint end time -> block of hits ··· 350 348 .filter(|k| k.deref() != "_counts") 351 349 } 352 350 353 - pub fn get_hits_debug(&self, nsid: &str) -> BoxedIter<AppResult<(Slice, Slice)>> { 354 - self.maybe_run_in_nsid_tree(nsid, |handle| -> BoxedIter<AppResult<(Slice, Slice)>> { 355 - Box::new( 351 + pub fn get_hits_debug(&self, nsid: &str) -> impl Iterator<Item = AppResult<(Slice, Slice)>> { 352 + self.maybe_run_in_nsid_tree(nsid, |handle| { 353 + Either::Left( 356 354 handle 357 355 .tree 358 356 .iter() ··· 360 358 .map(|res| res.map_err(AppError::from)), 361 359 ) 362 360 }) 363 - .unwrap_or_else(|| Box::new(std::iter::empty())) 361 + .unwrap_or_else(|| Either::Right(std::iter::empty())) 364 362 } 365 363 366 364 pub fn get_hits( 367 365 &self, 368 366 nsid: &str, 369 367 range: impl RangeBounds<u64> + std::fmt::Debug, 370 - ) -> BoxedIter<AppResult<Item>> { 368 + ) -> impl Iterator<Item = AppResult<Item>> { 371 369 let start = range 372 370 .start_bound() 373 371 .cloned() ··· 382 380 Bound::Unbounded => u64::MAX, 383 381 }; 384 382 385 - self.maybe_run_in_nsid_tree(nsid, move |handle| -> BoxedIter<AppResult<Item>> { 383 + self.maybe_run_in_nsid_tree(nsid, move |handle| { 386 384 let map_block = move |(key, val)| { 387 385 let mut key_reader = Cursor::new(key); 388 386 let start_timestamp = key_reader.read_varint::<u64>()?; ··· 393 391 Ok(items) 394 392 }; 395 393 396 - Box::new( 394 + Either::Left( 397 395 handle 398 396 .tree 399 397 .range(TimestampRange { start, end }) ··· 402 400 .flatten(), 403 401 ) 404 402 }) 405 - .unwrap_or_else(|| Box::new(std::iter::empty())) 403 + .unwrap_or_else(|| Either::Right(std::iter::empty())) 406 404 } 407 405 408 406 pub fn tracking_since(&self) -> AppResult<u64> {