Improved cache handling

This commit is contained in:
the-djmaze 2023-01-09 12:28:07 +01:00
parent 29854311f9
commit cf12960507
12 changed files with 153 additions and 145 deletions

View file

@ -130,11 +130,6 @@ export class AbstractFetchRemote
sGetAdd ? null : (params || {}),
undefined === iTimeout ? 30000 : pInt(iTimeout),
data => {
let cached = false;
if (data?.Time) {
cached = pInt(data.Time) > Date.now() - start;
}
let iError = 0;
if (sAction && oRequests[sAction]) {
abort(sAction, 0, 1);
@ -157,9 +152,12 @@ export class AbstractFetchRemote
fCallback && fCallback(
iError,
data,
cached,
sAction,
params
/**
* Responses like "304 Not Modified" are returned as "200 OK"
* This is an attempt to detect if the request comes from cache.
* But when client has wrong date/time, it will fail.
*/
data?.epoch && data.epoch < Math.floor(start / 1000) - 60
);
}
)
@ -203,8 +201,8 @@ export class AbstractFetchRemote
}
/*
let isCached = false, type = '';
if (data?.Time) {
isCached = pInt(data.Time) > microtime() - start;
if (data?.epoch) {
isCached = data.epoch > microtime() - start;
}
// backward capability
switch (true) {

View file

@ -9,57 +9,11 @@ import { SUB_QUERY_PREFIX } from 'Common/Links';
import { AppUserStore } from 'Stores/User/App';
import { SettingsUserStore } from 'Stores/User/Settings';
import { FolderUserStore } from 'Stores/User/Folder';
import { AbstractFetchRemote } from 'Remote/AbstractFetch';
class RemoteUserFetch extends AbstractFetchRemote {
/**
* @param {Function} fCallback
* @param {object} params
* @param {boolean=} bSilent = false
*/
messageList(fCallback, params, bSilent = false) {
const
sFolderFullName = pString(params.Folder),
folder = getFolderFromCacheList(sFolderFullName),
folderHash = folder?.hash || '';
params = Object.assign({
offset: 0,
limit: SettingsUserStore.messagesPerPage(),
search: '',
uidNext: folder?.uidNext || 0, // Used to check for new messages
sort: FolderUserStore.sortMode(),
Hash: folderHash + SettingsGet('AccountHash')
}, params);
params.Folder = sFolderFullName;
if (AppUserStore.threadsAllowed() && SettingsUserStore.useThreads()) {
params.useThreads = 1;
} else {
params.threadUid = 0;
}
let sGetAdd = '';
if (folderHash && (!params.search || !params.search.includes('is:'))) {
sGetAdd = 'MessageList/' +
SUB_QUERY_PREFIX +
'/' +
b64EncodeJSONSafe(params);
params = {};
}
bSilent || this.abort('MessageList');
this.request('MessageList',
fCallback,
params,
60000, // 60 seconds before aborting
sGetAdd
);
}
/**
* @param {?Function} fCallback
* @param {string} sFolderFullName