Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

get all collections

will add paging eventually

+18
ufos/src/server.rs
···
ok_cors(seen_by_collection)
}
+
/// Get all collections
+
///
+
/// TODO: paginate
+
#[endpoint {
+
method = GET,
+
path = "/collections/all"
+
}]
+
async fn get_all_collections(ctx: RequestContext<Context>) -> OkCorsResponse<Vec<Count>> {
+
let Context { storage, .. } = ctx.context();
+
let collections = storage
+
.get_all_collections(QueryPeriod::all_time())
+
.await
+
.map_err(|e| HttpError::for_internal_error(format!("oh shoot: {e:?}")))?;
+
+
ok_cors(collections)
+
}
+
/// Get top collections by record count
#[endpoint {
method = GET,
···
api.register(get_meta_info).unwrap();
api.register(get_records_by_collections).unwrap();
api.register(get_records_total_seen).unwrap();
+
api.register(get_all_collections).unwrap();
api.register(get_top_collections_by_count).unwrap();
api.register(get_top_collections_by_dids).unwrap();
api.register(get_top_collections).unwrap();
+2
ufos/src/storage.rs
···
async fn get_consumer_info(&self) -> StorageResult<ConsumerInfo>;
+
async fn get_all_collections(&self, period: QueryPeriod) -> StorageResult<Vec<Count>>;
+
async fn get_top_collections_by_count(
&self,
limit: usize,
+25
ufos/src/storage_fjall.rs
···
})
}
+
fn get_all_collections(&self, period: QueryPeriod) -> StorageResult<Vec<Count>> {
+
Ok(if period.is_all_time() {
+
let snapshot = self.rollups.snapshot();
+
let mut out = Vec::new();
+
let prefix = AllTimeRollupKey::from_prefix_to_db_bytes(&Default::default())?;
+
for kv in snapshot.prefix(prefix) {
+
let (key_bytes, val_bytes) = kv?;
+
let key = db_complete::<AllTimeRollupKey>(&key_bytes)?;
+
let db_counts = db_complete::<CountsValue>(&val_bytes)?;
+
out.push(Count {
+
thing: key.collection().to_string(),
+
records: db_counts.records(),
+
dids_estimate: db_counts.dids().estimate() as u64,
+
});
+
}
+
out
+
} else {
+
todo!()
+
})
+
}
+
fn get_top_collections_by_count(
&self,
limit: usize,
···
async fn get_consumer_info(&self) -> StorageResult<ConsumerInfo> {
let s = self.clone();
tokio::task::spawn_blocking(move || FjallReader::get_consumer_info(&s)).await?
+
}
+
async fn get_all_collections(&self, period: QueryPeriod) -> StorageResult<Vec<Count>> {
+
let s = self.clone();
+
tokio::task::spawn_blocking(move || FjallReader::get_all_collections(&s, period)).await?
}
async fn get_top_collections_by_count(
&self,
+3
ufos/src/storage_mem.rs
···
let s = self.clone();
tokio::task::spawn_blocking(move || MemReader::get_top_collections(&s)).await?
}
+
async fn get_all_collections(&self, _: QueryPeriod) -> StorageResult<Vec<Count>> {
+
todo!()
+
}
async fn get_top_collections_by_count(
&self,
_: usize,