Force catalog_items.offer_id to always equal its own row id
Every write path now sets offer_id = catalog_items.id instead of the sprite id or furnidata offerid: single import insert/update, clone import, upload import (direct DB + generated SQL migration), catalog repair inserts, reconcileImportedOfferIds and rebuildCatalogOfferIds. rebuildCatalogOfferIds is reduced to one bulk UPDATE that repairs any drift across all rows after every import; 74.838 legacy rows were repaired on the live database with this change.
This commit is contained in:
1 parent
adb56eb80b
commit
5311ee1fb8
10 files changed
+45
-103
No files matched your search
@@ -139,9 +139,10 @@ export const POST = withAdmin(
|
||||
}
|
||||
|
||||
// Post-import consolidation, mirroring the furni batch route:
|
||||
// keep offer_id / FurnitureData offerid in sync with the new local
|
||||
// sprite ids, verify interaction_modes_count, and refresh the
|
||||
// emulator + asset ownership. Never fails the stream — best effort.
|
||||
// force offer_id to mirror its catalog row id, keep the
|
||||
// FurnitureData in sync with the new local sprite ids, verify
|
||||
// interaction_modes_count, and refresh the emulator + asset
|
||||
// ownership. Never fails the stream — best effort.
|
||||
try {
|
||||
await reconcileImportedOfferIds();
|
||||
await reconcileFurniDataWithItemsBase();
|
||||
|
||||
@@ -272,7 +272,7 @@ export const POST = withAdmin(
|
||||
// Verify the furnidata matches the DB ids
|
||||
const furniReconcile = await reconcileFurniDataWithItemsBase();
|
||||
|
||||
// Rebuild every catalog offer_id from the furnidata
|
||||
// Force every catalog offer_id to equal its own row id
|
||||
const offerRebuild = await rebuildCatalogOfferIds();
|
||||
|
||||
// Repair any sprite_id drift so the client renders the right item
|
||||
|
||||
@@ -222,7 +222,7 @@ export const POST = withAdmin(
|
||||
}
|
||||
}
|
||||
|
||||
// Reconcile offer_id and fix asset ownership across the whole tree
|
||||
// Force offer_id to its row id and fix asset ownership across the tree
|
||||
let offerIdsFixed = 0;
|
||||
let ownershipFixed: string[] = [];
|
||||
let nitrosSynced: string[] = [];
|
||||
|
||||
@@ -501,7 +501,7 @@ export const POST = withAdmin(
|
||||
);
|
||||
}
|
||||
|
||||
// Reconcile offer_id with the furnidata sprite id across the tree
|
||||
// Force offer_id to mirror its catalog row id across the tree
|
||||
const reconciled = await reconcileImportedOfferIds();
|
||||
|
||||
// Keep asset + furnidata folders readable by the web server
|
||||
@@ -513,7 +513,7 @@ export const POST = withAdmin(
|
||||
// Verify the furnidata matches the DB ids
|
||||
const furniReconcile = await reconcileFurniDataWithItemsBase();
|
||||
|
||||
// Rebuild every catalog offer_id from the furnidata
|
||||
// Force every catalog offer_id to equal its own row id
|
||||
const offerRebuild = await rebuildCatalogOfferIds();
|
||||
|
||||
// Repair any sprite_id drift so the client renders the right item
|
||||
@@ -612,7 +612,7 @@ export const POST = withAdmin(
|
||||
result.warnings.push("RCON cache refresh failed");
|
||||
}
|
||||
|
||||
// Reconcile offer_id with the furnidata sprite id across the tree
|
||||
// Force offer_id to mirror its catalog row id across the tree
|
||||
const reconciled = await reconcileImportedOfferIds();
|
||||
|
||||
// Keep asset + furnidata folders readable by the web server
|
||||
@@ -628,7 +628,7 @@ export const POST = withAdmin(
|
||||
const { catalogNameFixed, haveOfferFixed, costCreditsFixed } =
|
||||
await fixDatabaseConsistencyAfterImport();
|
||||
|
||||
// Rebuild every catalog offer_id from the furnidata
|
||||
// Force every catalog offer_id to equal its own row id
|
||||
const offerRebuild = await rebuildCatalogOfferIds();
|
||||
|
||||
// Repair any sprite_id drift so the client renders the right item
|
||||
|
||||
@@ -408,10 +408,10 @@ export async function generateCatalogSql(
|
||||
const price = autoPriceFurni(entry.classname);
|
||||
// catalog_name must match items_base.item_name (the classname), exactly
|
||||
// like the app's own import pipeline, so the studio's in-catalog joins
|
||||
// and the emulator's item lookup stay consistent. offer_id is the item id
|
||||
// (sprite id), not a literal '-1'.
|
||||
// and the emulator's item lookup stay consistent. offer_id mirrors the
|
||||
// row's own id, never a literal '-1'.
|
||||
statements.push(
|
||||
`INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata) VALUES (${nextId}, ${pageId}, ${entry.itemId}, '${escSqlLiteral(entry.classname)}', ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${entry.itemId}, '');`,
|
||||
`INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata) VALUES (${nextId}, ${pageId}, ${entry.itemId}, '${escSqlLiteral(entry.classname)}', ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${nextId}, '');`,
|
||||
);
|
||||
nextId++;
|
||||
generated++;
|
||||
|
||||
@@ -458,7 +458,7 @@ export async function cloneSingleFurni(params: {
|
||||
await allocateCatalogItemId(async (nextCatalogId) => {
|
||||
await db.execute(sql`
|
||||
INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)
|
||||
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`);
|
||||
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${nextCatalogId}, '')`);
|
||||
return nextCatalogId;
|
||||
});
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -297,9 +297,9 @@ export function resetCatalogPageCache(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk every catalog item under the "Imported Furniture" tree and make its
|
||||
* offer_id match the furnidata sprite id (item_ids). Fixes any stale values
|
||||
* (e.g. legacy -1 rows) after an import.
|
||||
* Walk every catalog item under the "Imported Furniture" tree and force its
|
||||
* offer_id to equal its own catalog row id. Fixes any stale values (e.g.
|
||||
* legacy -1 rows) after an import.
|
||||
*/
|
||||
export async function reconcileImportedOfferIds(): Promise<{
|
||||
fixed: number;
|
||||
@@ -308,9 +308,9 @@ export async function reconcileImportedOfferIds(): Promise<{
|
||||
const [result] = (await db.execute(sql`
|
||||
UPDATE catalog_items ci
|
||||
JOIN catalog_pages cp ON cp.id = ci.page_id
|
||||
SET ci.offer_id = CAST(ci.item_ids AS UNSIGNED)
|
||||
SET ci.offer_id = ci.id
|
||||
WHERE cp.parent_id = ${parentId}
|
||||
AND ci.offer_id <> CAST(ci.item_ids AS UNSIGNED)
|
||||
AND ci.offer_id <> ci.id
|
||||
`)) as unknown as [Record<string, unknown>, unknown];
|
||||
return { fixed: Number(result.affectedRows ?? 0) };
|
||||
}
|
||||
@@ -1028,7 +1028,7 @@ export async function importSingleFurni(params: {
|
||||
const price = autoPriceFurni(classname);
|
||||
await db.execute(sql`
|
||||
UPDATE catalog_items
|
||||
SET page_id = ${pageIdStr}, cost_credits = ${price.credits}, cost_points = ${price.points}, points_type = ${price.pointsType}, offer_id = ${spriteId}
|
||||
SET page_id = ${pageIdStr}, cost_credits = ${price.credits}, cost_points = ${price.points}, points_type = ${price.pointsType}, offer_id = id
|
||||
WHERE id = ${catalogItemId}
|
||||
`);
|
||||
catalogUpdated = true;
|
||||
@@ -1048,7 +1048,7 @@ export async function importSingleFurni(params: {
|
||||
catalogItemId = await allocateCatalogItemId(async (nextCatalogId) => {
|
||||
await db.execute(sql`
|
||||
INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)
|
||||
VALUES (${nextCatalogId}, ${pageIdStr}, ${itemIdStr}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${spriteId}, '')
|
||||
VALUES (${nextCatalogId}, ${pageIdStr}, ${itemIdStr}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${nextCatalogId}, '')
|
||||
`);
|
||||
return nextCatalogId;
|
||||
});
|
||||
|
||||
@@ -282,15 +282,20 @@ describeGuard("live furni import / catalog ID consistency (sandbox DB)", () => {
|
||||
expect(row.spriteId).toBe(id);
|
||||
|
||||
const [catalog] = (await db.execute(sql`
|
||||
SELECT item_ids, catalog_name, offer_id FROM catalog_items WHERE item_ids = ${String(id)}
|
||||
SELECT id, item_ids, catalog_name, offer_id FROM catalog_items WHERE item_ids = ${String(id)}
|
||||
`)) as unknown as [
|
||||
Array<{ item_ids: string; catalog_name: string; offer_id: number }>,
|
||||
Array<{
|
||||
id: number;
|
||||
item_ids: string;
|
||||
catalog_name: string;
|
||||
offer_id: number;
|
||||
}>,
|
||||
unknown,
|
||||
];
|
||||
expect(catalog).toHaveLength(1);
|
||||
expect(catalog[0].item_ids).toBe(String(id));
|
||||
expect(catalog[0].catalog_name).toBe(classname);
|
||||
expect(catalog[0].offer_id).toBe(id);
|
||||
expect(catalog[0].offer_id).toBe(catalog[0].id);
|
||||
|
||||
// Re-import with updateExisting: previously fell through to an INSERT on
|
||||
// the existing PK and failed with "DB insert failed". Must now succeed.
|
||||
|
||||
@@ -206,7 +206,7 @@ async function writeSqlMigration(params: {
|
||||
`INSERT INTO catalog_items`,
|
||||
` (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)`,
|
||||
`SELECT (SELECT COALESCE(MAX(id), 0) + 1 FROM catalog_items), p.id, @next_id, ${escapeSql(params.classname)},`,
|
||||
` ${params.price.credits}, ${params.price.points}, ${params.price.pointsType}, 1, 1, @next_id, ''`,
|
||||
` ${params.price.credits}, ${params.price.points}, ${params.price.pointsType}, 1, 1, (SELECT COALESCE(MAX(id), 0) + 1 FROM catalog_items), ''`,
|
||||
`FROM catalog_pages p`,
|
||||
`WHERE p.caption_save = ${escapeSql(captionSave)};`,
|
||||
"",
|
||||
@@ -404,7 +404,7 @@ export async function uploadSingleFurni(params: {
|
||||
catalogItemId = await allocateCatalogItemId(async (nextCatalogId) => {
|
||||
await db.execute(sql`
|
||||
INSERT INTO catalog_items (id, page_id, item_ids, catalog_name, cost_credits, cost_points, points_type, amount, order_number, offer_id, extradata)
|
||||
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${newId}, '')`);
|
||||
VALUES (${nextCatalogId}, ${String(pageId)}, ${String(newId)}, ${classname}, ${price.credits}, ${price.points}, ${price.pointsType}, 1, 1, ${nextCatalogId}, '')`);
|
||||
return nextCatalogId;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user