use sequence numbers rather than timestamps for script expiration

This commit is contained in:
James Aguilar 2019-06-02 20:17:27 -04:00
parent 2201dfc371
commit d45689c7df
2 changed files with 6 additions and 3 deletions

@ -74,7 +74,7 @@ function shouldCompile(script, scripts) {
// compilation errors.
if (!depScript) return true;
const depIsMoreRecent = depScript.updateTimestamp > script.updateTimestamp
const depIsMoreRecent = depScript.moduleSequenceNumber > script.moduleSequenceNumber
return depIsMoreRecent;
});
}

@ -15,6 +15,8 @@ import {
} from "../../utils/JSONReviver";
import { roundToTwo } from "../../utils/helpers/roundToTwo";
let globalModuleSequenceNumber = 0;
export class Script {
// Initializes a Script Object from a JSON save state
static fromJSON(value: any): Script {
@ -32,7 +34,7 @@ export class Script {
module: any = "";
// The timestamp when when the script was last updated.
updateTimestamp: number = 0;
moduleSequenceNumber: number;
// Only used with NS2 scripts; the list of dependency script filenames. This is constructed
// whenever the script is first evaluated, and therefore may be out of date if the script
@ -51,6 +53,7 @@ export class Script {
this.ramUsage = 0;
this.server = server; // IP of server this script is on
this.module = "";
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
if (this.code !== "") { this.updateRamUsage(otherScripts); }
};
@ -101,7 +104,7 @@ export class Script {
// Marks that this script has been updated. Causes recompilation of NS2 modules.
markUpdated() {
this.module = "";
this.updateTimestamp = Date.now();
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
}
/**