+18
ufos/src/server.rs
+18
ufos/src/server.rs
···
213
213
ok_cors(seen_by_collection)
214
214
}
215
215
216
+
/// Get all collections
217
+
///
218
+
/// TODO: paginate
219
+
#[endpoint {
220
+
method = GET,
221
+
path = "/collections/all"
222
+
}]
223
+
async fn get_all_collections(ctx: RequestContext<Context>) -> OkCorsResponse<Vec<Count>> {
224
+
let Context { storage, .. } = ctx.context();
225
+
let collections = storage
226
+
.get_all_collections(QueryPeriod::all_time())
227
+
.await
228
+
.map_err(|e| HttpError::for_internal_error(format!("oh shoot: {e:?}")))?;
229
+
230
+
ok_cors(collections)
231
+
}
232
+
216
233
/// Get top collections by record count
217
234
#[endpoint {
218
235
method = GET,
···
274
291
api.register(get_meta_info).unwrap();
275
292
api.register(get_records_by_collections).unwrap();
276
293
api.register(get_records_total_seen).unwrap();
294
+
api.register(get_all_collections).unwrap();
277
295
api.register(get_top_collections_by_count).unwrap();
278
296
api.register(get_top_collections_by_dids).unwrap();
279
297
api.register(get_top_collections).unwrap();
+2
ufos/src/storage.rs
+2
ufos/src/storage.rs
+25
ufos/src/storage_fjall.rs
+25
ufos/src/storage_fjall.rs
···
372
372
})
373
373
}
374
374
375
+
fn get_all_collections(&self, period: QueryPeriod) -> StorageResult<Vec<Count>> {
376
+
Ok(if period.is_all_time() {
377
+
let snapshot = self.rollups.snapshot();
378
+
let mut out = Vec::new();
379
+
let prefix = AllTimeRollupKey::from_prefix_to_db_bytes(&Default::default())?;
380
+
for kv in snapshot.prefix(prefix) {
381
+
let (key_bytes, val_bytes) = kv?;
382
+
let key = db_complete::<AllTimeRollupKey>(&key_bytes)?;
383
+
let db_counts = db_complete::<CountsValue>(&val_bytes)?;
384
+
out.push(Count {
385
+
thing: key.collection().to_string(),
386
+
records: db_counts.records(),
387
+
dids_estimate: db_counts.dids().estimate() as u64,
388
+
});
389
+
}
390
+
out
391
+
} else {
392
+
todo!()
393
+
})
394
+
}
395
+
375
396
fn get_top_collections_by_count(
376
397
&self,
377
398
limit: usize,
···
572
593
async fn get_consumer_info(&self) -> StorageResult<ConsumerInfo> {
573
594
let s = self.clone();
574
595
tokio::task::spawn_blocking(move || FjallReader::get_consumer_info(&s)).await?
596
+
}
597
+
async fn get_all_collections(&self, period: QueryPeriod) -> StorageResult<Vec<Count>> {
598
+
let s = self.clone();
599
+
tokio::task::spawn_blocking(move || FjallReader::get_all_collections(&s, period)).await?
575
600
}
576
601
async fn get_top_collections_by_count(
577
602
&self,
+3
ufos/src/storage_mem.rs
+3
ufos/src/storage_mem.rs
···
594
594
let s = self.clone();
595
595
tokio::task::spawn_blocking(move || MemReader::get_top_collections(&s)).await?
596
596
}
597
+
async fn get_all_collections(&self, _: QueryPeriod) -> StorageResult<Vec<Count>> {
598
+
todo!()
599
+
}
597
600
async fn get_top_collections_by_count(
598
601
&self,
599
602
_: usize,