perf: cache public gallery views

This commit is contained in:
kdletters
2026-05-17 01:19:12 +08:00
parent d9c8473504
commit 81fe3dcf28
39 changed files with 2124 additions and 298 deletions

View File

@@ -7,7 +7,6 @@ use crate::module_bindings::record_big_fish_play_procedure::record_big_fish_play
use crate::module_bindings::remix_big_fish_work_procedure::remix_big_fish_work;
use crate::module_bindings::start_big_fish_run_procedure::start_big_fish_run;
use crate::module_bindings::submit_big_fish_input_procedure::submit_big_fish_input;
use module_big_fish::PUBLIC_BIG_FISH_GALLERY_OWNER_USER_ID;
impl SpacetimeClient {
pub async fn create_big_fish_session(
@@ -75,10 +74,29 @@ impl SpacetimeClient {
pub async fn list_big_fish_gallery(
&self,
) -> Result<Vec<BigFishWorkSummaryRecord>, SpacetimeClientError> {
self.list_big_fish_works_with_input(BigFishWorksListInput {
// 中文注释:公开广场读取只依赖 published_only但旧部署模块会先校验 owner_user_id 非空。
owner_user_id: PUBLIC_BIG_FISH_GALLERY_OWNER_USER_ID.to_string(),
published_only: true,
self.read_after_connect(move |connection| {
let recent_play_counts = public_work_recent_play_counts(connection, "big-fish");
let mut items = connection
.db()
.big_fish_gallery_view()
.iter()
.collect::<Vec<_>>();
items.sort_by(|left, right| {
right
.updated_at_micros
.cmp(&left.updated_at_micros)
.then_with(|| left.source_session_id.cmp(&right.source_session_id))
});
Ok(items
.into_iter()
.map(|item| {
let recent_play_count_7d = recent_play_counts
.get(&item.source_session_id)
.copied()
.unwrap_or(0);
map_big_fish_gallery_view_row(item, recent_play_count_7d)
})
.collect())
})
.await
}