perf(douyu): 降低商品能力同步写放大

This commit is contained in:
yml
2026-11-23 06:00:19 +08:00
parent 8e01c3c69e
commit 1e67111715
4 changed files with 157 additions and 65 deletions
+42
View File
@@ -217,6 +217,48 @@ def test_sync_account_goods_states_writes_capabilities_and_exchange_stats(db):
)
def test_sync_same_fresh_snapshot_does_not_rewrite_state(db):
account = _account(db, "cap-noop")
items = [{"commodityId": "A", "name": "商品 A", "status": "0"}]
first_changed = service.sync_account_goods_states(
db,
account,
items,
observed_at=NOW,
)
db.commit()
assert first_changed == 1
state = db.query(AccountCommodityState).filter_by(account_id=account.id).one()
assert state.observed_at == NOW
repeated_changed = service.sync_account_goods_states(
db,
account,
items,
observed_at=NOW + timedelta(minutes=1),
)
db.commit()
assert repeated_changed == 0
db.refresh(state)
assert state.observed_at == NOW
refreshed_at = NOW + timedelta(hours=7)
expired_changed = service.sync_account_goods_states(
db,
account,
items,
observed_at=refreshed_at,
)
db.commit()
assert expired_changed == 1
db.refresh(state)
assert state.observed_at == refreshed_at
def test_next_sync_marks_missing_goods_not_offered(db):
account = _account(db, "cap-remove")
service.sync_account_goods_states(