From 4d6d0622e5951d5434af5097241911b59c0cd48e Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 26 Oct 2021 15:43:27 +0200 Subject: [PATCH] Speedup generating folderlist --- dev/Model/FolderCollection.js | 6 ++---- dev/Settings/User/Folders.js | 7 +++++-- dev/Stores/User/Folder.js | 12 ----------- dev/View/User/MailBox/FolderList.js | 21 +++++++++++++++++-- .../Views/User/MailFolderListItem.html | 4 +++- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index f31be3849..251458f61 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -297,7 +297,7 @@ export class FolderModel extends AbstractModel { visible: () => folder.hasSubscriptions() | !SettingsUserStore.hideUnsubscribed(), - isSystemFolder: () => FolderType.User !== folder.type() || !!folder.kolabType(), + isSystemFolder: () => FolderType.User !== folder.type() | !!folder.kolabType(), hidden: () => { let hasSubFolders = folder.hasSubscribedSubfolders(); @@ -354,9 +354,7 @@ export class FolderModel extends AbstractModel { }, collapsed: { - read: () => folder.isInbox() && FolderUserStore.singleRootFolder() - ? false - : !folder.hidden() && folder.collapsedPrivate(), + read: () => !folder.hidden() && folder.collapsedPrivate(), write: value => folder.collapsedPrivate(value) }, diff --git a/dev/Settings/User/Folders.js b/dev/Settings/User/Folders.js index cf48eb545..89c6839e1 100644 --- a/dev/Settings/User/Folders.js +++ b/dev/Settings/User/Folders.js @@ -22,6 +22,8 @@ import { showScreenPopup } from 'Knoin/Knoin'; import { FolderCreatePopupView } from 'View/Popup/FolderCreate'; import { FolderSystemPopupView } from 'View/Popup/FolderSystem'; +const folderForDeletion = ko.observable(null).deleteAccessHelper(); + export class FoldersUserSettings /*extends AbstractViewSettings*/ { constructor() { this.showKolab = Settings.capa(Capa.Kolab) && FolderUserStore.metadataSupported(); @@ -56,7 +58,7 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ { return loading || creating || deleting || renaming; }); - this.folderForDeletion = ko.observable(null).deleteAccessHelper(); + this.folderForDeletion = folderForDeletion; this.folderForEdit = ko.observable(null).extend({ toggleSubscribeProperty: [this, 'edited'] }); @@ -111,7 +113,7 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ { folderToRemove.deleteAccess() && 0 === folderToRemove.privateMessageCountAll() ) { - this.folderForDeletion(null); + folderForDeletion(null); if (folderToRemove) { Local.set(ClientSideKeyName.FoldersLashHash, ''); @@ -123,6 +125,7 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ { () => { folderToRemove.selectable(false) removeFolderFromCacheList(folderToRemove.fullNameRaw); + FolderUserStore.folderList(FolderUserStore.folderList.filter(folder => folder !== folderToRemove)); }, error => { FolderUserStore.folderListError( diff --git a/dev/Stores/User/Folder.js b/dev/Stores/User/Folder.js index 0c3a44dfe..4ad414fc9 100644 --- a/dev/Stores/User/Folder.js +++ b/dev/Stores/User/Folder.js @@ -57,18 +57,6 @@ export const FolderUserStore = new class { draftFolderNotEnabled: () => !this.draftFolder() || UNUSED_OPTION_VALUE === this.draftFolder(), - // foldersListWithSingleInboxRootFolder - /** returns true when there are no non-system folders in the root of the folders tree */ - singleRootFolder: () => { - let multiple = false; - this.folderList.forEach(folder => { - let subscribed = folder.subscribed(), - hasSub = folder.hasSubscribedSubfolders(); - multiple |= (!folder.isSystemFolder() || (hasSub && !folder.isInbox())) && (subscribed || hasSub) - }); - return !multiple; - }, - currentFolderFullNameRaw: () => (this.currentFolder() ? this.currentFolder().fullNameRaw : ''), currentFolderFullName: () => (this.currentFolder() ? this.currentFolder().fullName : ''), diff --git a/dev/View/User/MailBox/FolderList.js b/dev/View/User/MailBox/FolderList.js index 83fc6d42f..8b6e2e2d8 100644 --- a/dev/View/User/MailBox/FolderList.js +++ b/dev/View/User/MailBox/FolderList.js @@ -33,7 +33,7 @@ export class MailFolderList extends AbstractViewLeft { this.moveAction = moveAction; - this.foldersListWithSingleInboxRootFolder = FolderUserStore.singleRootFolder; + this.foldersListWithSingleInboxRootFolder = ko.observable(false); this.leftPanelDisabled = leftPanelDisabled; @@ -42,7 +42,24 @@ export class MailFolderList extends AbstractViewLeft { addComputablesTo(this, { folderListFocused: () => Scope.FolderList === AppUserStore.focusedState(), - folderListVisible: () => FolderUserStore.folderList().filter(v => !(v.hidden() || v.kolabType())) + folderListVisible: () => { + let multiple = false, + inbox, subscribed, hasSub, + result = FolderUserStore.folderList().filter(folder => { + if (folder.isInbox()) { + inbox = folder; + } + subscribed = folder.subscribed(); + hasSub = folder.hasSubscribedSubfolders(); + multiple |= (!folder.isSystemFolder() || (hasSub && !folder.isInbox())) && (subscribed || hasSub) + return !(folder.hidden() | folder.kolabType()); + }); + if (inbox && !multiple) { + inbox.collapsedPrivate(false); + } + this.foldersListWithSingleInboxRootFolder(!multiple); + return result; + } }); } diff --git a/snappymail/v/0.0.0/app/templates/Views/User/MailFolderListItem.html b/snappymail/v/0.0.0/app/templates/Views/User/MailFolderListItem.html index 22975a596..3bf8984dd 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/MailFolderListItem.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/MailFolderListItem.html @@ -1,4 +1,5 @@ -
  • + +
  • @@ -9,3 +10,4 @@
    • +