Compare commits

..

1 Commits

Author SHA1 Message Date
QuentinHsu
bac04587b8 🐞 fix(subscriptions): negative usage flow 2022-10-23 13:36:01 +08:00
3 changed files with 17 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.13.6", "version": "2.13.5",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@@ -16,13 +16,8 @@ class ResourceCache {
let clear = false; let clear = false;
Object.entries(this.resourceCache).forEach((entry) => { Object.entries(this.resourceCache).forEach((entry) => {
const [id, updated] = entry; const [id, updated] = entry;
if (!updated.time) { if (new Date().getTime() - updated > this.expires) {
// clear old version cache
delete this.resourceCache[id];
$.delete(`#${id}`); $.delete(`#${id}`);
clear = true;
}
if (new Date().getTime() - updated.time > this.expires) {
delete this.resourceCache[id]; delete this.resourceCache[id];
clear = true; clear = true;
} }
@@ -31,6 +26,9 @@ class ResourceCache {
} }
revokeAll() { revokeAll() {
Object.keys(this.resourceCache).forEach((id) => {
$.delete(`#${id}`);
});
this.resourceCache = {}; this.resourceCache = {};
this._persist(); this._persist();
} }
@@ -40,16 +38,17 @@ class ResourceCache {
} }
get(id) { get(id) {
const updated = this.resourceCache[id] && this.resourceCache[id].time; const updated = this.resourceCache[id];
if (updated && new Date().getTime() - updated <= this.expires) { if (updated && new Date().getTime() - updated <= this.expires) {
return this.resourceCache[id].data; return $.read(`#${id}`);
} }
return null; return null;
} }
set(id, value) { set(id, value) {
this.resourceCache[id] = { time: new Date().getTime(), data: value } this.resourceCache[id] = new Date().getTime();
this._persist(); this._persist();
$.write(value, `#${id}`);
} }
} }

View File

@@ -17,13 +17,8 @@ class ResourceCache {
let clear = false; let clear = false;
Object.entries(this.resourceCache).forEach((entry) => { Object.entries(this.resourceCache).forEach((entry) => {
const [id, updated] = entry; const [id, updated] = entry;
if (!updated.time) { if (new Date().getTime() - updated > this.expires) {
// clear old version cache
delete this.resourceCache[id];
$.delete(`#${id}`); $.delete(`#${id}`);
clear = true;
}
if (new Date().getTime() - updated.time > this.expires) {
delete this.resourceCache[id]; delete this.resourceCache[id];
clear = true; clear = true;
} }
@@ -32,6 +27,9 @@ class ResourceCache {
} }
revokeAll() { revokeAll() {
Object.keys(this.resourceCache).forEach((id) => {
$.delete(`#${id}`);
});
this.resourceCache = {}; this.resourceCache = {};
this._persist(); this._persist();
} }
@@ -41,16 +39,17 @@ class ResourceCache {
} }
get(id) { get(id) {
const updated = this.resourceCache[id] && this.resourceCache[id].time; const updated = this.resourceCache[id];
if (updated && new Date().getTime() - updated <= this.expires) { if (updated && new Date().getTime() - updated <= this.expires) {
return this.resourceCache[id].data; return $.read(`#${id}`);
} }
return null; return null;
} }
set(id, value) { set(id, value) {
this.resourceCache[id] = { time: new Date().getTime(), data: value } this.resourceCache[id] = new Date().getTime();
this._persist(); this._persist();
$.write(value, `#${id}`);
} }
} }