aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-02-26 18:35:57 -0500
committerDeterminant <[email protected]>2019-02-26 18:35:57 -0500
commite0a4f8eeeb3a60ad5cac0f78694df29c1f27c943 (patch)
tree2ead5e807960e70933b65585423cdf5685ca42e9 /src
parentd017bbd1ad19345af0121f8bb0cf805f977e55f6 (diff)
fix cache saving issue
Diffstat (limited to 'src')
-rw-r--r--src/background.ts4
-rw-r--r--src/gapi.ts22
2 files changed, 19 insertions, 7 deletions
diff --git a/src/background.ts b/src/background.ts
index a9fed12..3c37865 100644
--- a/src/background.ts
+++ b/src/background.ts
@@ -135,7 +135,7 @@ async function getCalEvents(id: string, start: Date, end: Date) {
let gcal = getCalData(id);
try {
let res = await gcal.getEvents(new Date(start), new Date(end));
- dirtyCalData = res.changed;
+ dirtyCalData = dirtyCalData || res.changed;
return res.events;
} catch(err) {
handleGApiError(id, err);
@@ -192,7 +192,7 @@ async function pollSync() {
console.log(`cannot sync calendar ${id}`);
}));
}
- await Promise.all(pms);
+ (await Promise.all(pms)).forEach(b => b && (dirtyCalData = true));
/* update the tracked graph data */
await updateMainGraphData();
pms = [];
diff --git a/src/gapi.ts b/src/gapi.ts
index 116d873..82de1ee 100644
--- a/src/gapi.ts
+++ b/src/gapi.ts
@@ -436,7 +436,8 @@ export class GCalendar {
return results;
}
- async sync() {
+ async sync(): Promise<boolean> {
+ let changed = false;
try {
let token = await this.token;
let r = await getEvents(this.calId, token, this.syncToken);
@@ -446,15 +447,24 @@ export class GCalendar {
e.start = new Date(e.start.dateTime);
e.end = new Date(e.end.dateTime);
if (e.status === 'confirmed')
+ {
this.addEvent(e);
+ changed = true;
+ }
else if (e.status === 'cancelled')
+ {
this.removeEvent(e);
+ changed = true;
+ }
});
+ if (this.syncToken !== r.nextSyncToken)
+ changed = true;
this.syncToken = r.nextSyncToken;
+ return changed;
} catch(err) {
if (err === GApiError.invalidSyncToken) {
this.syncToken = '';
- this.sync();
+ return this.sync();
} else throw err;
}
}
@@ -518,10 +528,12 @@ export class GCalendar {
}
else
{
- console.log(`cache hit`);
- if (sync) await this.sync();
+ let changed = false;
+ if (sync)
+ changed = await this.sync();
let events = await this.getCachedEvents({ start, end });
- return { events, changed: false };
+ console.log(`cache hit sync:${sync} changed:${changed}`);
+ return { events, changed };
}
}
}