perf: speed up batch furniture import
- Run batch imports with bounded concurrency (IMPORT_BATCH_CONCURRENCY = 8) instead of fully sequentially, parallelizing network downloads and DB writes. - Collect FurnitureData.json entries and write the whole file once per batch (appendFurniEntriesBulk) instead of rewriting it on every single item. Catalog id allocation stays serialized and FurnitureData writes remain lock-guarded, so concurrent imports are safe.
This commit is contained in:
1 parent
488f40919d
commit
6843af235e
2 files changed
+95
-18
No files matched your search
@@ -317,6 +317,37 @@ export async function appendFurniEntry(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Append many FurnitureData entries in a single read/parse/write cycle
|
||||
* (under the furnidata lock). Used by batch imports so the whole JSON file
|
||||
* is rewritten once instead of once per item.
|
||||
*/
|
||||
export async function appendFurniEntriesBulk(
|
||||
entries: Array<{ entry: Record<string, unknown>; itemType: string }>,
|
||||
): Promise<void> {
|
||||
if (entries.length === 0) return;
|
||||
await withFurniDataLock(async () => {
|
||||
const furniData = (await readFurniData()) as Record<
|
||||
string,
|
||||
{ furnitype: Array<Record<string, unknown>> }
|
||||
>;
|
||||
const existingOwners = furniDataIdOwners(furniData);
|
||||
assertNoFurniDataIdConflicts(existingOwners, entries);
|
||||
for (const { entry, itemType } of entries) {
|
||||
if (itemType === "i") {
|
||||
if (!furniData.wallitemtypes)
|
||||
furniData.wallitemtypes = { furnitype: [] };
|
||||
upsertEntryInSection(furniData.wallitemtypes, entry);
|
||||
} else {
|
||||
if (!furniData.roomitemtypes)
|
||||
furniData.roomitemtypes = { furnitype: [] };
|
||||
upsertEntryInSection(furniData.roomitemtypes, entry);
|
||||
}
|
||||
}
|
||||
await writeFurniData(furniData as Record<string, unknown>);
|
||||
});
|
||||
}
|
||||
|
||||
export async function removeFurniEntry(classname: string): Promise<boolean> {
|
||||
return withFurniDataLock(async () => {
|
||||
const furniData = (await readFurniData()) as Record<
|
||||
|
||||
Reference in new issue
Block a user