Merge pull request 'feat(prefetch): kalici vehicles.fully_fetched kolonu (migration 0034)' (#250) from dev into main
This commit was merged in pull request #250.
This commit is contained in:
9
apps/api/drizzle/0034_vehicle_fully_fetched.sql
Normal file
9
apps/api/drizzle/0034_vehicle_fully_fetched.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Kalıcı tamlık işareti: prefetch zinciri parça ile bittiğinde true olur
|
||||
-- (PrefetchWorkerService.incrementCompleted). Redis prefetch:complete:* (21g TTL,
|
||||
-- operasyonel skip mantığı) yerine SÜRESİZ ölçüm — "% tam çekilmiş" güvenilir
|
||||
-- takibi. _at son doğrulanma zamanını tutar. IF NOT EXISTS → idempotent.
|
||||
ALTER TABLE "vehicles" ADD COLUMN IF NOT EXISTS "fully_fetched" boolean DEFAULT false NOT NULL;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "vehicles" ADD COLUMN IF NOT EXISTS "fully_fetched_at" timestamp with time zone;
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "vehicles_fully_fetched_idx" ON "vehicles" USING btree ("fully_fetched");
|
||||
@@ -239,6 +239,13 @@
|
||||
"when": 1784027180912,
|
||||
"tag": "0033_parts_oem_code_norm_idx",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 34,
|
||||
"version": "7",
|
||||
"when": 1784965129879,
|
||||
"tag": "0034_vehicle_fully_fetched",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -419,10 +419,20 @@ export const vehicles = pgTable(
|
||||
market: varchar("market", { length: 100 }),
|
||||
rawData: jsonb("raw_data"),
|
||||
source: varchar("source", { length: 20 }).default("pl24").notNull(),
|
||||
// Durable completeness marker: set true when the prefetch chain finishes with
|
||||
// parts (see PrefetchWorkerService.incrementCompleted). Unlike the ephemeral
|
||||
// Redis `prefetch:complete:*` marker (21-day TTL, operational skip logic) this
|
||||
// never expires — it's the reliable "% fully fetched" measurement. `_at` tracks
|
||||
// the last time completion was confirmed (re-set on each re-drill completion).
|
||||
fullyFetched: boolean("fully_fetched").default(false).notNull(),
|
||||
fullyFetchedAt: timestamp("fully_fetched_at", { withTimezone: true }),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
||||
},
|
||||
(table) => [uniqueIndex("vehicles_vin_unique_idx").on(table.vin)],
|
||||
(table) => [
|
||||
uniqueIndex("vehicles_vin_unique_idx").on(table.vin),
|
||||
index("vehicles_fully_fetched_idx").on(table.fullyFetched),
|
||||
],
|
||||
);
|
||||
|
||||
// ─── User Vehicles (junction — user ↔ shared vehicle) ─
|
||||
|
||||
@@ -841,6 +841,13 @@ export class PrefetchWorkerService implements OnModuleInit, OnModuleDestroy {
|
||||
// isFinished, so partially-fetched vehicles are never marked — they keep
|
||||
// getting gap-filled.
|
||||
await this.redis.set(this.completeKey(vehicleId), "1", COMPLETE_TTL_S);
|
||||
// Durable completeness flag (never expires) — the reliable "% fully
|
||||
// fetched" measurement, independent of the ephemeral Redis marker.
|
||||
// Re-set on every re-drill completion so fullyFetchedAt tracks last-verified.
|
||||
await this.db
|
||||
.update(vehicles)
|
||||
.set({ fullyFetched: true, fullyFetchedAt: new Date() })
|
||||
.where(eq(vehicles.id, vehicleId));
|
||||
} else {
|
||||
await this.markNoResult(vehicleId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user