This commit is contained in:
2026-05-13 03:10:55 +08:00
154 changed files with 16812 additions and 708 deletions

View File

@@ -1,8 +1,9 @@
use crate::runtime::{
ProfilePlayedWorkUpsertInput, ProfileSaveArchiveUpsertInput, PublicWorkLikeRecordInput,
PublicWorkPlayRecordInput, add_profile_observed_play_time, count_recent_public_work_plays,
grant_profile_wallet_points, record_public_work_like, record_public_work_play,
upsert_profile_played_work, upsert_profile_save_archive,
count_recent_public_work_plays_for_profiles, grant_profile_wallet_points,
record_public_work_like, record_public_work_play, upsert_profile_played_work,
upsert_profile_save_archive,
};
use module_puzzle::{
PUZZLE_MAX_TAG_COUNT, PUZZLE_NEXT_LEVEL_MODE_NONE, PUZZLE_NEXT_LEVEL_MODE_SAME_WORK,
@@ -1480,12 +1481,21 @@ fn delete_puzzle_work_tx(
fn list_puzzle_gallery_tx(ctx: &TxContext) -> Result<Vec<PuzzleWorkProfile>, String> {
let now_micros = ctx.timestamp.to_micros_since_unix_epoch();
let mut items = ctx
let rows = ctx
.db
.puzzle_work_profile()
.iter()
.filter(|row| row.publication_status == PuzzlePublicationStatus::Published)
.map(|row| build_puzzle_work_profile_from_row_with_recent_count(ctx, &row, now_micros))
.collect::<Vec<_>>();
let profile_ids = rows
.iter()
.map(|row| row.profile_id.clone())
.collect::<Vec<_>>();
let recent_play_counts =
count_recent_public_work_plays_for_profiles(ctx, "puzzle", &profile_ids, now_micros);
let mut items = rows
.iter()
.map(|row| build_puzzle_work_profile_from_row_with_recent_counts(row, &recent_play_counts))
.collect::<Result<Vec<_>, _>>()?;
items.sort_by(|left, right| right.updated_at_micros.cmp(&left.updated_at_micros));
Ok(items)
@@ -2356,6 +2366,18 @@ fn build_puzzle_work_profile_from_row_with_recent_count(
Ok(profile)
}
fn build_puzzle_work_profile_from_row_with_recent_counts(
row: &PuzzleWorkProfileRow,
recent_play_counts: &std::collections::HashMap<String, u32>,
) -> Result<PuzzleWorkProfile, String> {
let mut profile = build_puzzle_work_profile_from_row_without_recent_count(row)?;
profile.recent_play_count_7d = recent_play_counts
.get(&row.profile_id)
.copied()
.unwrap_or(0);
Ok(profile)
}
fn build_puzzle_work_profile_from_row_without_recent_count(
row: &PuzzleWorkProfileRow,
) -> Result<PuzzleWorkProfile, String> {