Apply recipe notification deltas directly in Lua

Review feedback: the download field now always carries the delta and the deserializer applies it against the current state instead of rebuilding the full list first. The previous failed recipe names are passed in so they survive the round trip. The version check moved to the call site.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Fable 5.1 committed 2026-09-11 19:26:38 +00:00
1 parent 1272c0e8e4
commit bb36af08fe
5 files changed
+69 -109

No files matched your search

+6 -8
View File
@@ -217,19 +217,19 @@ export class InstancePlugin extends BaseInstancePlugin {
* Replace the stored recipe notifications with the difference from the
* current state on the instance to reduce the amount of data sent to Lua.
*/
async applyRecipeNotificationDelta(playerData: IpcPlayerData, current: string) {
async applyRecipeNotificationDelta(playerData: IpcPlayerData, current?: string) {
if (!playerData.recipe_notifications) {
return;
}
try {
const delta = recipeNotificationDelta(
JSON.parse(await decodeLuaString(playerData.recipe_notifications)),
JSON.parse(await decodeLuaString(current)),
current ? JSON.parse(await decodeLuaString(current)) : [],
);
playerData.recipe_notifications_delta = await encodeLuaString(JSON.stringify(delta));
delete playerData.recipe_notifications;
playerData.recipe_notifications = await encodeLuaString(JSON.stringify(delta));
} catch (err: any) {
this.logger.warn(`Sending full recipe notifications for ${playerData.name}:\n${err.stack}`);
this.logger.warn(`Dropping invalid recipe notifications for ${playerData.name}:\n${err.stack}`);
delete playerData.recipe_notifications;
}
}
@@ -247,9 +247,7 @@ export class InstancePlugin extends BaseInstancePlugin {
return;
}
if (request.recipe_notifications) {
await this.applyRecipeNotificationDelta(response.playerData, request.recipe_notifications);
}
await this.applyRecipeNotificationDelta(response.playerData, request.recipe_notifications);
const chunkSize = this.instance.config.get("inventory_sync.rcon_chunk_size");
const chunks = chunkify(chunkSize, JSON.stringify(response.playerData));