mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-28 19:49:20 +03:00
Offload server CPU to client when fetching folder list
This commit is contained in:
parent
32712415ef
commit
c8e4d589cb
8 changed files with 59 additions and 197 deletions
|
|
@ -73,15 +73,11 @@ export const SetSystemFoldersNotification = {
|
|||
* @enum {number}
|
||||
*/
|
||||
export const ClientSideKeyName = {
|
||||
FoldersLashHash: 0,
|
||||
MessagesInboxLastHash: 1,
|
||||
MailBoxListSize: 2,
|
||||
ExpandedFolders: 3,
|
||||
FolderListSize: 4,
|
||||
MessageListSize: 5,
|
||||
LastReplyAction: 6,
|
||||
LastSignMe: 7,
|
||||
ComposeLastIdentityID: 8,
|
||||
MessageHeaderFullInfo: 9,
|
||||
MessageAttachmentControls: 10
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { AbstractCollectionModel } from 'Model/AbstractCollection';
|
|||
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
|
||||
import { isArray, getKeyByValue, forEachObjectEntry, b64EncodeJSONSafe } from 'Common/Utils';
|
||||
import { ClientSideKeyName, FolderType, FolderMetadataKeys } from 'Common/EnumsUser';
|
||||
import * as Cache from 'Common/Cache';
|
||||
import { getFolderFromCacheList, setFolder, setFolderInboxName, setFolderHash } from 'Common/Cache';
|
||||
import { Settings, SettingsGet } from 'Common/Globals';
|
||||
|
||||
import * as Local from 'Storage/Client';
|
||||
|
|
@ -25,7 +25,7 @@ import { AbstractModel } from 'Knoin/AbstractModel';
|
|||
const
|
||||
normalizeFolder = sFolderFullName => ('' === sFolderFullName
|
||||
|| UNUSED_OPTION_VALUE === sFolderFullName
|
||||
|| null !== Cache.getFolderFromCacheList(sFolderFullName))
|
||||
|| null !== getFolderFromCacheList(sFolderFullName))
|
||||
? sFolderFullName
|
||||
: '';
|
||||
|
||||
|
|
@ -44,7 +44,6 @@ export class FolderCollectionModel extends AbstractCollectionModel
|
|||
constructor() {
|
||||
super();
|
||||
this.CountRec
|
||||
this.FoldersHash
|
||||
this.IsThreadsSupported
|
||||
this.Namespace;
|
||||
this.Optimized
|
||||
|
|
@ -65,23 +64,20 @@ export class FolderCollectionModel extends AbstractCollectionModel
|
|||
);
|
||||
}
|
||||
|
||||
return super.reviveFromJson(object, oFolder => {
|
||||
let oCacheFolder = Cache.getFolderFromCacheList(oFolder.FullName),
|
||||
const result = super.reviveFromJson(object, oFolder => {
|
||||
let oCacheFolder = getFolderFromCacheList(oFolder.FullName),
|
||||
type = FolderType[getKeyByValue(SystemFolders, oFolder.FullName)];
|
||||
|
||||
if (oCacheFolder) {
|
||||
oFolder.SubFolders = FolderCollectionModel.reviveFromJson(oFolder.SubFolders);
|
||||
oFolder.SubFolders && oCacheFolder.subFolders(oFolder.SubFolders);
|
||||
} else {
|
||||
if (!oCacheFolder) {
|
||||
oCacheFolder = FolderModel.reviveFromJson(oFolder);
|
||||
if (!oCacheFolder)
|
||||
return null;
|
||||
|
||||
if (1 == type) {
|
||||
oCacheFolder.type(FolderType.Inbox);
|
||||
Cache.setFolderInboxName(oFolder.FullName);
|
||||
setFolderInboxName(oFolder.FullName);
|
||||
}
|
||||
Cache.setFolder(oCacheFolder);
|
||||
setFolder(oCacheFolder);
|
||||
}
|
||||
|
||||
if (1 < type) {
|
||||
|
|
@ -94,7 +90,7 @@ export class FolderCollectionModel extends AbstractCollectionModel
|
|||
|
||||
if (oFolder.Extended) {
|
||||
if (oFolder.Extended.Hash) {
|
||||
Cache.setFolderHash(oCacheFolder.fullName, oFolder.Extended.Hash);
|
||||
setFolderHash(oCacheFolder.fullName, oFolder.Extended.Hash);
|
||||
}
|
||||
|
||||
if (null != oFolder.Extended.MessageCount) {
|
||||
|
|
@ -107,6 +103,31 @@ export class FolderCollectionModel extends AbstractCollectionModel
|
|||
}
|
||||
return oCacheFolder;
|
||||
});
|
||||
|
||||
let i = result.length;
|
||||
if (i) {
|
||||
try {
|
||||
let collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
|
||||
result.sort((a, b) =>
|
||||
a.isInbox() ? -1 : (b.isInbox() ? 1 : collator.compare(a.fullName, b.fullName))
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
try {
|
||||
while (i--) {
|
||||
let folder = result[i], parent = getFolderFromCacheList(folder.parentName);
|
||||
if (parent) {
|
||||
parent.subFolders.unshift(folder);
|
||||
result.splice(i,1);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
storeIt() {
|
||||
|
|
@ -141,8 +162,6 @@ export class FolderCollectionModel extends AbstractCollectionModel
|
|||
FolderUserStore.archiveFolder(normalizeFolder(SystemFolders.Archive));
|
||||
|
||||
// FolderUserStore.folderList.valueHasMutated();
|
||||
|
||||
Local.set(ClientSideKeyName.FoldersLashHash, this.FoldersHash);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { Notification } from 'Common/Enums';
|
||||
import { ClientSideKeyName, FolderMetadataKeys } from 'Common/EnumsUser';
|
||||
import { FolderMetadataKeys } from 'Common/EnumsUser';
|
||||
import { Settings } from 'Common/Globals';
|
||||
import { getNotification } from 'Common/Translator';
|
||||
|
||||
|
|
@ -10,8 +10,6 @@ import { Capa } from 'Common/Enums';
|
|||
import { defaultOptionsAfterRender } from 'Common/Utils';
|
||||
import { initOnStartOrLangChange, i18n } from 'Common/Translator';
|
||||
|
||||
import * as Local from 'Storage/Client';
|
||||
|
||||
import { FolderUserStore } from 'Stores/User/Folder';
|
||||
import { SettingsUserStore } from 'Stores/User/Settings';
|
||||
|
||||
|
|
@ -70,7 +68,6 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ {
|
|||
const nameToEdit = folder ? folder.nameForEdit().trim() : '';
|
||||
|
||||
if (nameToEdit && folder.name() !== nameToEdit) {
|
||||
Local.set(ClientSideKeyName.FoldersLashHash, '');
|
||||
Remote.abort('Folders').post('FolderRename', FolderUserStore.foldersRenaming, {
|
||||
Folder: folder.fullName,
|
||||
NewFolderName: nameToEdit
|
||||
|
|
@ -136,8 +133,6 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ {
|
|||
folderForDeletion(null);
|
||||
|
||||
if (folderToRemove) {
|
||||
Local.set(ClientSideKeyName.FoldersLashHash, '');
|
||||
|
||||
Remote.abort('Folders').post('FolderDelete', FolderUserStore.foldersDeleting, {
|
||||
Folder: folderToRemove.fullName
|
||||
}).then(
|
||||
|
|
@ -174,7 +169,6 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ {
|
|||
|
||||
toggleFolderSubscription(folder) {
|
||||
let subscribe = !folder.subscribed();
|
||||
Local.set(ClientSideKeyName.FoldersLashHash, '');
|
||||
Remote.request('FolderSubscribe', null, {
|
||||
Folder: folder.fullName,
|
||||
Subscribe: subscribe ? 1 : 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue