Skip to content

Commit

Permalink
enhancement: persist only when protection changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sush1lemon committed Nov 21, 2024
1 parent 758b901 commit 6418e46
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions server/src/services/maproom/v2/damageProtection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,32 @@ export const damageProtection = async (save: Save, mode?: BaseMode) => {
// Check if 12 hours have passed since outpost takeover
const isOutpostProtectionOver = currentTime - createtime > twelveHours;

let persist = false;

const setProtection = () => {
protection = 1;
mainProtectionTime = currentTime;
persist = true;
};

const removeProtection = () => {
protection = 0;
mainProtectionTime = null;
save.initialProtectionOver = true;
persist = true
};

const setOutpostProtection = () => {
protection = 1;
outpostProtectionTime = currentTime;
persist = true;
};

const removeOutpostProtection = () => {
protection = 0;
outpostProtectionTime = null;
save.initialOutpostProtectionOver = true;
persist = true
};

if (mode === BaseMode.ATTACK) {
Expand All @@ -66,6 +72,7 @@ export const damageProtection = async (save: Save, mode?: BaseMode) => {
save.initialOutpostProtectionOver = true;
if (mainProtectionTime) mainProtectionTime = null;
if (outpostProtectionTime) outpostProtectionTime = null;
persist = true;
} else {
switch (type) {
case BaseType.MAIN:
Expand Down Expand Up @@ -129,10 +136,12 @@ export const damageProtection = async (save: Save, mode?: BaseMode) => {
}
}

save.protected = protection;
save.mainProtectionTime = mainProtectionTime;
save.outpostProtectionTime = outpostProtectionTime;
await ORMContext.em.persistAndFlush(save);
if (persist) {
save.protected = protection;
save.mainProtectionTime = mainProtectionTime;
save.outpostProtectionTime = outpostProtectionTime;
await ORMContext.em.persistAndFlush(save);
}

return protection;
};

0 comments on commit 6418e46

Please sign in to comment.