feat(api-server): cache puzzle gallery card view

This commit is contained in:
kdletters
2026-05-17 05:50:33 +08:00
parent 02271e6c73
commit 73f937d78a
17 changed files with 771 additions and 44 deletions

View File

@@ -402,24 +402,28 @@ impl SpacetimeClient {
pub async fn list_puzzle_gallery(
&self,
) -> Result<Vec<PuzzleWorkProfileRecord>, SpacetimeClientError> {
) -> Result<Vec<PuzzleGalleryCardRecord>, SpacetimeClientError> {
self.read_after_connect(move |connection| {
let mut items = connection
.db()
.puzzle_gallery_view()
.puzzle_gallery_card_view()
.iter()
.collect::<Vec<_>>();
items.sort_by(|left, right| right.updated_at_micros.cmp(&left.updated_at_micros));
items.sort_by(|left, right| {
right
.updated_at_micros
.cmp(&left.updated_at_micros)
.then_with(|| left.profile_id.cmp(&right.profile_id))
});
let recent_play_counts = public_work_recent_play_counts(connection, "puzzle");
Ok(items
.into_iter()
.map(|item| {
let mut record = map_puzzle_work_profile_row(item);
record.recent_play_count_7d = recent_play_counts
.get(&record.profile_id)
let recent_play_count_7d = recent_play_counts
.get(&item.profile_id)
.copied()
.unwrap_or(0);
record
map_puzzle_gallery_card_view_row(item, recent_play_count_7d)
})
.collect())
})