Merge pull request #2738 from bobrippling/popcon-tweaks
popcon: trim old entries from the cachemaster
commit
603b24e5f4
|
|
@ -1 +1,2 @@
|
|||
0.01: New App!
|
||||
0.02: Trim old entries from the popcon app cache
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@ Popcon
|
|||
|
||||
Display apps sorted by regular use. No config - install the app and all your launchers will sort apps by most popular, based off launch counts within the last month, and then sort them by the most recently launched app.
|
||||
|
||||
:warning: Warning: this app overrides [`Storage.readJSON`], so may slow down your watch when using apps that perform I/O.
|
||||
⚠️ Warning: this app overrides [`Storage.readJSON`], so may slow down your watch when using apps that perform I/O.
|
||||
|
||||
[`Storage.readJSON`]: https://www.espruino.com/ReferenceBANGLEJS2#l_Storage_readJSON
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
var oldRead_1 = require("Storage").readJSON;
|
||||
var monthAgo_1 = Date.now() - 1000 * 86400 * 28;
|
||||
var oneMonth_1 = 1000 * 86400 * 28;
|
||||
var monthAgo_1 = Date.now() - oneMonth_1;
|
||||
var cache_1;
|
||||
var ensureCache_1 = function () {
|
||||
if (!cache_1) {
|
||||
|
|
@ -10,8 +11,20 @@
|
|||
}
|
||||
return cache_1;
|
||||
};
|
||||
var saveCache_1 = function (orderChanged) {
|
||||
require("Storage").writeJSON("popcon.cache.json", cache_1);
|
||||
var trimCache_1 = function (cache) {
|
||||
var threeMonthsBack = Date.now() - oneMonth_1 * 3;
|
||||
var del = [];
|
||||
for (var k in cache)
|
||||
if (cache[k].last < threeMonthsBack)
|
||||
del.push(k);
|
||||
for (var _i = 0, del_1 = del; _i < del_1.length; _i++) {
|
||||
var k = del_1[_i];
|
||||
delete cache[k];
|
||||
}
|
||||
};
|
||||
var saveCache_1 = function (cache, orderChanged) {
|
||||
trimCache_1(cache);
|
||||
require("Storage").writeJSON("popcon.cache.json", cache);
|
||||
if (orderChanged) {
|
||||
var info = oldRead_1("popcon.info", true);
|
||||
info.cacheBuster = !info.cacheBuster;
|
||||
|
|
@ -74,7 +87,7 @@
|
|||
ent.pop++;
|
||||
ent.last = Date.now();
|
||||
var orderChanged = sortCache_1();
|
||||
saveCache_1(orderChanged);
|
||||
saveCache_1(cache_3, orderChanged);
|
||||
}
|
||||
return oldLoad_1(src);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
{
|
||||
type Timestamp = number;
|
||||
|
||||
const oldRead = require("Storage").readJSON;
|
||||
const monthAgo = Date.now() - 1000 * 86400 * 28;
|
||||
let cache: undefined | {
|
||||
type Cache = {
|
||||
[key: string]: {
|
||||
sortorder: number,
|
||||
pop: number, // amount of launches
|
||||
|
|
@ -11,6 +8,11 @@ let cache: undefined | {
|
|||
}
|
||||
};
|
||||
|
||||
const oldRead = require("Storage").readJSON;
|
||||
const oneMonth = 1000 * 86400 * 28;
|
||||
const monthAgo = Date.now() - oneMonth;
|
||||
let cache: undefined | Cache;
|
||||
|
||||
const ensureCache = (): NonNull<typeof cache> => {
|
||||
if(!cache){
|
||||
cache = oldRead("popcon.cache.json", true);
|
||||
|
|
@ -20,7 +22,19 @@ const ensureCache = (): NonNull<typeof cache> => {
|
|||
return cache;
|
||||
};
|
||||
|
||||
const saveCache = (orderChanged: boolean) => {
|
||||
const trimCache = (cache: Cache) => {
|
||||
const threeMonthsBack = Date.now() - oneMonth * 3;
|
||||
const del = [];
|
||||
for(const k in cache)
|
||||
if(cache[k]!.last < threeMonthsBack)
|
||||
del.push(k);
|
||||
|
||||
for(const k of del)
|
||||
delete cache[k];
|
||||
};
|
||||
|
||||
const saveCache = (cache: Cache, orderChanged: boolean) => {
|
||||
trimCache(cache);
|
||||
require("Storage").writeJSON("popcon.cache.json", cache);
|
||||
if(orderChanged){
|
||||
// ensure launchers reload their caches:
|
||||
|
|
@ -94,7 +108,7 @@ global.load = (src: string) => {
|
|||
ent.pop++;
|
||||
ent.last = Date.now();
|
||||
const orderChanged = sortCache();
|
||||
saveCache(orderChanged);
|
||||
saveCache(cache, orderChanged);
|
||||
}
|
||||
|
||||
return oldLoad(src);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"id": "popconlaunch",
|
||||
"name": "Popcon Launcher",
|
||||
"shortName": "Popcon",
|
||||
"version": "0.01",
|
||||
"version": "0.02",
|
||||
"description": "Launcher modification - your launchers will display your favourite (popular) apps first. Overrides `readJSON`, may slow down your watch",
|
||||
"readme": "README.md",
|
||||
"icon": "app.png",
|
||||
|
|
|
|||
Loading…
Reference in New Issue