perf: Move collection sorting to frontend (#3475)

* perf: Move collection sorting to frontend, on demand, memoized

* fix: Add default
This commit is contained in:
Tom Moor
2022-05-01 08:30:16 -07:00
committed by GitHub
parent 5cd4ecd34a
commit 25dce04046
9 changed files with 85 additions and 59 deletions

View File

@@ -1,5 +1,6 @@
import { trim } from "lodash";
import { action, computed, observable } from "mobx";
import { sortNavigationNodes } from "@shared/utils/collections";
import CollectionsStore from "~/stores/CollectionsStore";
import Document from "~/models/Document";
import ParanoidModel from "~/models/ParanoidModel";
@@ -95,6 +96,11 @@ export default class Collection extends ParanoidModel {
);
}
@computed
get sortedDocuments() {
return sortNavigationNodes(this.documents, this.sort);
}
@action
updateDocument(document: Document) {
const travelNodes = (nodes: NavigationNode[]) =>
@@ -130,7 +136,7 @@ export default class Collection extends ParanoidModel {
};
if (this.documents) {
travelNodes(this.documents);
travelNodes(this.sortedDocuments);
}
return result;