Select the types of activity you want to include in your feed.
pass in time bounds and remove memstore
idk why these are the same commit, except that i'm finally annoyed enough at stubbing the memstore to remove it. it wasn't ever that real since it was just a hacked copy of the fjall stuff.
···66pub mod server;
77pub mod storage;
88pub mod storage_fjall;
99-pub mod storage_mem;
109pub mod store_types;
11101211use crate::error::BatchInsertError;
+17-57
ufos/src/main.rs
···77use ufos::server;
88use ufos::storage::{StorageWhatever, StoreBackground, StoreReader, StoreWriter};
99use ufos::storage_fjall::FjallStorage;
1010-use ufos::storage_mem::MemStorage;
1110use ufos::store_types::SketchSecretPrefix;
1211use ufos::{nice_duration, ConsumerInfo};
1312···1918static GLOBAL: Jemalloc = Jemalloc;
20192120/// Aggregate links in the at-mosphere
2222-#[derive(Parser, Debug)]
2121+#[derive(Parser, Debug, Clone)]
2322#[command(version, about, long_about = None)]
2423struct Args {
2524 /// Jetstream server to connect to (exclusive with --fixture). Provide either a wss:// URL, or a shorhand value:
···4746 /// todo: restore this
4847 #[arg(long, action)]
4948 pause_rw: bool,
5050- /// DEBUG: use an in-memory store instead of fjall
5151- #[arg(long, action)]
5252- in_mem: bool,
5349 /// reset the rollup cursor, scrape through missed things in the past (backfill)
5450 #[arg(long, action)]
5551 reroll: bool,
···64606561 let args = Args::parse();
6662 let jetstream = args.jetstream.clone();
6767- if args.in_mem {
6868- let (read_store, write_store, cursor, sketch_secret) = MemStorage::init(
6969- args.data,
7070- jetstream,
7171- args.jetstream_force,
7272- Default::default(),
7373- )?;
7474- go(
7575- args.jetstream,
7676- args.jetstream_fixture,
7777- args.pause_writer,
7878- args.backfill,
7979- args.reroll,
8080- read_store,
8181- write_store,
8282- cursor,
8383- sketch_secret,
8484- )
8585- .await?;
8686- } else {
8787- let (read_store, write_store, cursor, sketch_secret) = FjallStorage::init(
8888- args.data,
8989- jetstream,
9090- args.jetstream_force,
9191- Default::default(),
9292- )?;
9393- go(
9494- args.jetstream,
9595- args.jetstream_fixture,
9696- args.pause_writer,
9797- args.backfill,
9898- args.reroll,
9999- read_store,
100100- write_store,
101101- cursor,
102102- sketch_secret,
103103- )
104104- .await?;
105105- }
106106-6363+ let (read_store, write_store, cursor, sketch_secret) = FjallStorage::init(
6464+ args.data.clone(),
6565+ jetstream,
6666+ args.jetstream_force,
6767+ Default::default(),
6868+ )?;
6969+ go(args, read_store, write_store, cursor, sketch_secret).await?;
10770 Ok(())
10871}
10972110110-#[allow(clippy::too_many_arguments)]
11173async fn go<B: StoreBackground>(
112112- jetstream: String,
113113- jetstream_fixture: bool,
114114- pause_writer: bool,
115115- backfill: bool,
116116- reroll: bool,
7474+ args: Args,
11775 read_store: impl StoreReader + 'static + Clone,
11876 mut write_store: impl StoreWriter<B> + 'static,
11977 cursor: Option<Cursor>,
···12280 println!("starting server with storage...");
12381 let serving = server::serve(read_store.clone());
12482125125- if pause_writer {
8383+ if args.pause_writer {
12684 log::info!("not starting jetstream or the write loop.");
12785 serving.await.map_err(|e| anyhow::anyhow!(e))?;
12886 return Ok(());
12987 }
13088131131- let batches = if jetstream_fixture {
132132- log::info!("starting with jestream file fixture: {jetstream:?}");
133133- file_consumer::consume(jetstream.into(), sketch_secret, cursor).await?
8989+ let batches = if args.jetstream_fixture {
9090+ log::info!("starting with jestream file fixture: {:?}", args.jetstream);
9191+ file_consumer::consume(args.jetstream.into(), sketch_secret, cursor).await?
13492 } else {
13593 log::info!(
13694 "starting consumer with cursor: {cursor:?} from {:?} ago",
13795 cursor.map(|c| c.elapsed())
13896 );
139139- consumer::consume(&jetstream, cursor, false, sketch_secret).await?
9797+ consumer::consume(&args.jetstream, cursor, false, sketch_secret).await?
14098 };
14199142142- let rolling = write_store.background_tasks(reroll)?.run(backfill);
100100+ let rolling = write_store
101101+ .background_tasks(args.reroll)?
102102+ .run(args.backfill);
143103 let storing = write_store.receive_batches(batches);
144104145105 let stating = do_update_stuff(read_store);
+8-3
ufos/src/server/mod.rs
···232232 let q = query.into_inner();
233233 let collections: HashSet<Nsid> = collections_query.try_into()?;
234234235235- let _since = q.since.map(dt_to_cursor).transpose()?;
236236- let _until = q.until.map(dt_to_cursor).transpose()?;
235235+ let since = q.since.map(dt_to_cursor).transpose()?.unwrap_or_else(|| {
236236+ let week_ago_secs = 7 * 86_400;
237237+ let week_ago = SystemTime::now() - Duration::from_secs(week_ago_secs);
238238+ Cursor::at(week_ago).into()
239239+ });
240240+241241+ let until = q.until.map(dt_to_cursor).transpose()?;
237242238243 let mut seen_by_collection = HashMap::with_capacity(collections.len());
239244240245 for collection in &collections {
241246 let (total_creates, dids_estimate) = storage
242242- .get_counts_by_collection(collection)
247247+ .get_counts_by_collection(collection, since, until)
243248 .await
244249 .map_err(|e| HttpError::for_internal_error(format!("boooo: {e:?}")))?;
245250