mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Improved cache handling
This commit is contained in:
parent
29854311f9
commit
cf12960507
12 changed files with 153 additions and 145 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue