diff --git a/furniture-3d-system/src/server/services/__tests__/supply-chain-clearance-price-push.service.test.ts b/furniture-3d-system/src/server/services/__tests__/supply-chain-clearance-price-push.service.test.ts index ff16a21a..bf54838b 100644 --- a/furniture-3d-system/src/server/services/__tests__/supply-chain-clearance-price-push.service.test.ts +++ b/furniture-3d-system/src/server/services/__tests__/supply-chain-clearance-price-push.service.test.ts @@ -261,7 +261,8 @@ describe('supply chain clearance price push service', () => { }], }), }) - const service = new SupplyChainClearancePricePushService(repo, { getTasks: jest.fn() } as never) + const taskReader = { getTasks: jest.fn() } + const service = new SupplyChainClearancePricePushService(repo, taskReader as never) await expect(service.getPage({ periodKey: '2026-11', page: 1, pageSize: 50 })) .resolves.toMatchObject({ @@ -274,6 +275,8 @@ describe('supply chain clearance price push service', () => { historicalCostPrice: 60, }], }) + expect(repo.replaceSnapshot).not.toHaveBeenCalled() + expect(taskReader.getTasks).not.toHaveBeenCalled() }) it('restores abnormal prior-month discounted products to their cost price', async () => { diff --git a/furniture-3d-system/src/server/services/supply-chain-clearance-price-push.service.ts b/furniture-3d-system/src/server/services/supply-chain-clearance-price-push.service.ts index 4ed55d95..a2a3002f 100644 --- a/furniture-3d-system/src/server/services/supply-chain-clearance-price-push.service.ts +++ b/furniture-3d-system/src/server/services/supply-chain-clearance-price-push.service.ts @@ -15,8 +15,6 @@ import { } from './supply-chain-clearance.service' const PERIOD_PATTERN = /^\d{4}-(0[1-9]|1[0-2])$/ -const AUTO_SYNC_TTL_MS = 5 * 60 * 1_000 -const lastAutomaticSyncAt = new Map() type PricePushRepository = Pick< typeof supplyChainClearancePricePushRepository, @@ -77,37 +75,10 @@ export class SupplyChainClearancePricePushService { pageSize?: number filters?: ClearancePricePushFilters }) { - const requestedPeriod = PERIOD_PATTERN.test(String(input.periodKey ?? '').trim()) - ? String(input.periodKey).trim() - : '' - if (requestedPeriod) { - const lastSyncAt = lastAutomaticSyncAt.get(requestedPeriod) ?? 0 - if (Date.now() - lastSyncAt >= AUTO_SYNC_TTL_MS) { - try { - await this.syncApprovedTasks(requestedPeriod) - } catch (error) { - console.error('[clearance-price-push] automatic task sync failed', { - periodKey: requestedPeriod, - error, - }) - } - } - } - let snapshots = await this.repository.listSnapshots() + const snapshots = await this.repository.listSnapshots() const periodKey = PERIOD_PATTERN.test(String(input.periodKey ?? '').trim()) ? String(input.periodKey).trim() : snapshots[0]?.periodKey ?? shanghaiPeriodKey() - if (!snapshots.some((snapshot) => snapshot.periodKey === periodKey)) { - try { - await this.syncApprovedTasks(periodKey) - snapshots = await this.repository.listSnapshots() - } catch (error) { - console.error('[clearance-price-push] initial task sync failed', { - periodKey, - error, - }) - } - } const page = Math.max(1, Math.floor(input.page ?? 1)) const pageSize = Math.min(200, Math.max(20, Math.floor(input.pageSize ?? 50))) try { @@ -281,7 +252,6 @@ export class SupplyChainClearancePricePushService { generatedByName: input.user.name, items: plan.items, }) - lastAutomaticSyncAt.set(periodKey, Date.now()) return { periodKey, startDate: `${periodKey}-01`,