From 6f0d773ddeec360fd85bce0fe4ff62a11919a77f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Sat, 3 Oct 2026 16:27:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=E6=A1=A3=E4=BD=8D=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=A7=8D=E5=AD=90=E6=94=B9=E7=94=B1=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=92=AD=E7=A7=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 init 生命周期 reducer,数据库首次创建时把 profile_membership_plan 整表播种 membership_plan_row 与 membership_plan_records 去掉懒播种,只读路径不再写库 ensure_default_profile_recharge_product_config 不再顺带初始化会员目录 存量数据库此前已由懒播种写入目录行,新建数据库由 init reducer 播种 --- .../spacetime-module/src/runtime/active/profile.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server-rs/crates/spacetime-module/src/runtime/active/profile.rs b/server-rs/crates/spacetime-module/src/runtime/active/profile.rs index 737d1ff0c..48d64193c 100644 --- a/server-rs/crates/spacetime-module/src/runtime/active/profile.rs +++ b/server-rs/crates/spacetime-module/src/runtime/active/profile.rs @@ -8812,8 +8812,16 @@ fn ensure_default_profile_membership_plan(ctx: &ReducerContext) { } } -fn ensure_default_profile_recharge_product_config(ctx: &ReducerContext) { +/// 模块初始化生命周期:只在数据库首次创建时把会员档位目录整表播种。 +/// +/// 迁移目的:报价 / 充值中心 / 后台查询等只读入口不再调用 `ensure_default_profile_membership_plan` +/// 写库;存量数据库此前已由懒播种写入了目录行,新建数据库则由本 reducer 播种。 +#[spacetimedb::reducer(init)] +pub fn init_profile_membership_plan_catalog(ctx: &ReducerContext) { ensure_default_profile_membership_plan(ctx); +} + +fn ensure_default_profile_recharge_product_config(ctx: &ReducerContext) { if ctx.db.profile_recharge_product_config().count() > 0 { migrate_legacy_default_profile_recharge_product_config(ctx); return; @@ -9146,7 +9154,6 @@ fn membership_plan_row( ctx: &ReducerContext, plan: RuntimeProfileMembershipPlan, ) -> Option { - ensure_default_profile_membership_plan(ctx); ctx.db.profile_membership_plan().plan().find(&plan) } @@ -9186,9 +9193,8 @@ fn membership_plan_snapshot( }) } -/// 充值中心与后台共用的目录行读取,按 `rank` 升序。 +/// 充值中心与后台共用的目录行读取,按 `rank` 升序;只读,不再触发表为空时的懒播种。 fn membership_plan_records(ctx: &ReducerContext) -> Vec { - ensure_default_profile_membership_plan(ctx); let mut rows = ctx.db.profile_membership_plan().iter().collect::>(); rows.sort_by(|left, right| { left.rank