aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2020-10-22 22:23:39 -0400
committerbobzel <zzzman@gmail.com>2020-10-22 22:23:39 -0400
commit749873972fba8ed8d5b34b73b43947d6356b882e (patch)
tree94d134e71f67645d7e5b4159a13097115f7d3be5
parente97f4446446672bec1c8330b081f2a38d292f260 (diff)
added more caching for linkManager queries.
-rw-r--r--src/client/util/CurrentUserUtils.ts4
-rw-r--r--src/client/util/LinkManager.ts106
-rw-r--r--src/client/views/collections/CollectionMenu.tsx2
-rw-r--r--src/client/views/collections/CollectionSubView.tsx2
-rw-r--r--src/client/views/collections/TabDocView.tsx2
5 files changed, 33 insertions, 83 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 07447b93c..5886aa13f 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -1125,7 +1125,7 @@ export class CurrentUserUtils {
DocListCastAsync(importDocs.data).then(async list => {
const results = await DocUtils.uploadFilesToDocs(Array.from(input.files || []), {});
if (results.length !== input.files?.length) {
- alert("Error uploading files - possibly due to unsupported file types")
+ alert("Error uploading files - possibly due to unsupported file types");
}
list?.splice(0, 0, ...results);
disposer();
@@ -1212,7 +1212,5 @@ Scripting.addGlobal(function createNewPresentation() { return MainView.Instance.
"creates a new presentation when called");
Scripting.addGlobal(function links(doc: any) { return new List(LinkManager.Instance.getAllRelatedLinks(doc)); },
"returns all the links to the document or its annotations", "(doc: any)");
-Scripting.addGlobal(function directLinks(doc: any) { return new List(LinkManager.Instance.getAllDirectLinks(doc)); },
- "returns all the links directly to the document", "(doc: any)");
Scripting.addGlobal(function importDocument() { return CurrentUserUtils.importDocument(); },
"imports files from device directly into the import sidebar");
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index 1ba6cff6d..c3ab7c6e7 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -25,94 +25,52 @@ export class LinkManager {
public static currentLink: Opt<Doc>;
- public static get Instance(): LinkManager {
- return this._instance || (this._instance = new this());
- }
-
- private constructor() {
- }
-
+ public static get Instance(): LinkManager { return this._instance || (this._instance = new this()); }
- public getAllLinks(): Doc[] {
- const lset = new Set<Doc>(DocListCast(Doc.LinkDBDoc().data));
- SharingManager.Instance.users.forEach(user => {
- DocListCast(user.linkDatabase?.data).map(doc => {
- lset.add(doc);
- });
- });
- return Array.from(lset);
- }
+ public addLink(linkDoc: Doc) { return Doc.AddDocToList(Doc.LinkDBDoc(), "data", linkDoc); }
- public addLink(linkDoc: Doc): boolean {
- return Doc.AddDocToList(Doc.LinkDBDoc(), "data", linkDoc);
- }
+ public deleteLink(linkDoc: Doc) { return Doc.RemoveDocFromList(Doc.LinkDBDoc(), "data", linkDoc); }
- public deleteLink(linkDoc: Doc): boolean {
- return Doc.RemoveDocFromList(Doc.LinkDBDoc(), "data", linkDoc);
- }
+ public deleteAllLinksOnAnchor(anchor: Doc) { LinkManager.Instance.getAllRelatedLinks(anchor).forEach(linkDoc => LinkManager.Instance.deleteLink(linkDoc)); }
- // finds all links that contain the given anchor
- public getAllDirectLinks(anchor: Doc): Doc[] {
- const related = LinkManager.Instance.getAllLinks().filter(link => link).filter(link => {
- const a1 = Cast(link.anchor1, Doc, null);
- const a2 = Cast(link.anchor2, Doc, null);
- const protomatch1 = Doc.AreProtosEqual(anchor, a1);
- const protomatch2 = Doc.AreProtosEqual(anchor, a2);
- return ((a1?.author !== undefined && a2?.author !== undefined) || link.author === Doc.CurrentUserEmail) && (protomatch1 || protomatch2 || Doc.AreProtosEqual(link, anchor));
- });
- return related;
- }
+ public getAllRelatedLinks(anchor: Doc) { return this.relatedLinker(anchor); } // finds all links that contain the given anchor
- relatedLinker = computedFn(function realtedLinker(this: any, anchor: Doc) {
- const related = LinkManager.Instance.getAllDirectLinks(anchor);
- DocListCast(anchor[Doc.LayoutFieldKey(anchor) + "-annotations"]).map(anno => {
- related.push(...LinkManager.Instance.getAllRelatedLinks(anno));
- });
- return related;
- }.bind(this), true);
+ public getAllDirectLinks(anchor: Doc): Doc[] { return this.directLinker(anchor); } // finds all links that contain the given anchor
- // finds all links that contain the given anchor
- public getAllRelatedLinks(anchor: Doc): Doc[] {
- return this.relatedLinker(anchor);
- }
+ public getAllLinks(): Doc[] { return this.allLinks(); }
- public deleteAllLinksOnAnchor(anchor: Doc) {
- const related = LinkManager.Instance.getAllRelatedLinks(anchor);
- related.forEach(linkDoc => LinkManager.Instance.deleteLink(linkDoc));
- }
+ allLinks = computedFn(function allLinks(this: any) {
+ const lset = new Set<Doc>(DocListCast(Doc.LinkDBDoc().data));
+ SharingManager.Instance.users.forEach(user => DocListCast(user.linkDatabase?.data).map(doc => lset.add(doc)));
+ return Array.from(lset);
+ }, true);
- // gets the groups associates with an anchor in a link
- public getAnchorGroups(linkDoc: Doc, anchor?: Doc): Array<Doc> {
- if (Doc.AreProtosEqual(anchor, Cast(linkDoc.anchor1, Doc, null))) {
- return DocListCast(linkDoc.anchor1Groups);
- } else {
- return DocListCast(linkDoc.anchor2Groups);
- }
- }
- public addGroupToAnchor(linkDoc: Doc, anchor: Doc, groupDoc: Doc, replace: boolean = false) {
- Doc.GetProto(linkDoc).linkRelationship = groupDoc.linkRelationship;
- }
+ directLinker = computedFn(function directLinker(this: any, anchor: Doc) {
+ return LinkManager.Instance.getAllLinks().filter(link => {
+ const a1 = Cast(link?.anchor1, Doc, null);
+ const a2 = Cast(link?.anchor2, Doc, null);
+ return link && ((a1?.author !== undefined && a2?.author !== undefined) || link.author === Doc.CurrentUserEmail) && (Doc.AreProtosEqual(anchor, a1) || Doc.AreProtosEqual(anchor, a2) || Doc.AreProtosEqual(link, anchor));
+ });
+ }, true);
- // removes group doc of given group type only from given anchor on given link
- public removeGroupFromAnchor(linkDoc: Doc, anchor: Doc, groupType: string) {
- Doc.GetProto(linkDoc).linkRelationship = "-ungrouped-";
- }
+ relatedLinker = computedFn(function relatedLinker(this: any, anchor: Doc) {
+ const related = LinkManager.Instance.directLinker(anchor);
+ DocListCast(anchor[Doc.LayoutFieldKey(anchor) + "-annotations"]).map(anno => related.push(...LinkManager.Instance.getAllRelatedLinks(anno)));
+ return related;
+ }, true);
// returns map of group type to anchor's links in that group type
public getRelatedGroupedLinks(anchor: Doc): Map<string, Array<Doc>> {
- const related = this.getAllRelatedLinks(anchor);
const anchorGroups = new Map<string, Array<Doc>>();
- related.forEach(link => {
+ this.getAllRelatedLinks(anchor).forEach(link => {
if (!link.linkRelationship || link?.linkRelationship !== "-ungrouped-") {
const group = anchorGroups.get(StrCast(link.linkRelationship));
anchorGroups.set(StrCast(link.linkRelationship), group ? [...group, link] : [link]);
-
} else {
// if link is in no groups then put it in default group
const group = anchorGroups.get("*");
anchorGroups.set("*", group ? [...group, link] : [link]);
}
-
});
return anchorGroups;
}
@@ -120,21 +78,15 @@ export class LinkManager {
// returns a list of all metadata docs associated with the given group type
public getAllMetadataDocsInGroup(groupType: string): Array<Doc> {
const md: Doc[] = [];
- const allLinks = LinkManager.Instance.getAllLinks();
- allLinks.forEach(linkDoc => {
- if (StrCast(linkDoc.linkRelationship).toUpperCase() === groupType.toUpperCase()) { md.push(linkDoc); }
- });
+ LinkManager.Instance.getAllLinks().forEach(linkDoc => StrCast(linkDoc.linkRelationship).toUpperCase() === groupType.toUpperCase() && md.push(linkDoc));
return md;
}
// checks if a link with the given anchors exists
public doesLinkExist(anchor1: Doc, anchor2: Doc): boolean {
- const allLinks = LinkManager.Instance.getAllLinks();
- const index = allLinks.findIndex(linkDoc => {
- return (Doc.AreProtosEqual(Cast(linkDoc.anchor1, Doc, null), anchor1) && Doc.AreProtosEqual(Cast(linkDoc.anchor2, Doc, null), anchor2)) ||
- (Doc.AreProtosEqual(Cast(linkDoc.anchor1, Doc, null), anchor2) && Doc.AreProtosEqual(Cast(linkDoc.anchor2, Doc, null), anchor1));
- });
- return index !== -1;
+ return -1 !== LinkManager.Instance.getAllLinks().findIndex(linkDoc =>
+ (Doc.AreProtosEqual(Cast(linkDoc.anchor1, Doc, null), anchor1) && Doc.AreProtosEqual(Cast(linkDoc.anchor2, Doc, null), anchor2)) ||
+ (Doc.AreProtosEqual(Cast(linkDoc.anchor1, Doc, null), anchor2) && Doc.AreProtosEqual(Cast(linkDoc.anchor2, Doc, null), anchor1)));
}
// finds the opposite anchor of a given anchor in a link
diff --git a/src/client/views/collections/CollectionMenu.tsx b/src/client/views/collections/CollectionMenu.tsx
index fed9be062..abad23e0d 100644
--- a/src/client/views/collections/CollectionMenu.tsx
+++ b/src/client/views/collections/CollectionMenu.tsx
@@ -429,7 +429,7 @@ export class CollectionViewBaseChrome extends React.Component<CollectionMenuProp
const presPinWithViewIcon = <img src={`/assets/pinWithView.png`} style={{ margin: "auto", width: 19 }} />;
const targetDoc = this.selectedDoc;
{/* return (!targetDoc || (targetDoc._viewType !== CollectionViewType.Freeform && targetDoc.type !== DocumentType.IMG)) ? (null) : <Tooltip title={<><div className="dash-tooltip">{"Pin to presentation trail with current view"}</div></>} placement="top"> */ }
- return (targetDoc && targetDoc.type !== DocumentType.PRES && (targetDoc._viewType === CollectionViewType.Freeform || targetDoc._viewType === CollectionViewType.Stacking || targetDoc.type === DocumentType.VID || targetDoc.type === DocumentType.IMG || targetDoc.type === DocumentType.PDF || targetDoc.type === DocumentType.WEB || targetDoc.type === DocumentType.VIDEO || targetDoc.type === DocumentType.RTF || targetDoc.type === DocumentType.COMPARISON)) ? <Tooltip title={<><div className="dash-tooltip">{"Pin to presentation trail with current view"}</div></>} placement="top">
+ return (targetDoc && targetDoc.type !== DocumentType.PRES && (targetDoc._viewType === CollectionViewType.Freeform || targetDoc._viewType === CollectionViewType.Stacking || targetDoc.type === DocumentType.VID || targetDoc.type === DocumentType.IMG || targetDoc.type === DocumentType.PDF || targetDoc.type === DocumentType.WEB || targetDoc.type === DocumentType.VID || targetDoc.type === DocumentType.RTF || targetDoc.type === DocumentType.COMPARISON)) ? <Tooltip title={<><div className="dash-tooltip">{"Pin to presentation trail with current view"}</div></>} placement="top">
<button className="antimodeMenu-button" style={{ borderRight: "1px solid gray", borderLeft: "1px solid gray", justifyContent: 'center' }}
onClick={() => this.pinWithView(targetDoc)}>
{presPinWithViewIcon}
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 0dd033e47..f88ebd9ac 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -483,7 +483,7 @@ export function CollectionSubView<T, X>(schemaCtor: (doc: Doc) => T, moreProps?:
if (text && !text.includes("https://")) {
UndoManager.RunInBatch(() => this.addDocument(Docs.Create.TextDocument(text, { ...options, title: text.substring(0, 20), _width: 400, _height: 315 })), "drop");
} else {
- alert("Document updloaded failed - possibly an unsupported file type.")
+ alert("Document updloaded failed - possibly an unsupported file type.");
}
}
disposer();
diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx
index ff1e077ff..5bdf19a31 100644
--- a/src/client/views/collections/TabDocView.tsx
+++ b/src/client/views/collections/TabDocView.tsx
@@ -218,7 +218,7 @@ export class TabDocView extends React.Component<TabDocViewProps> {
}
@computed get panelWidth() {
return this.layoutDoc?.maxWidth ? Math.min(Math.max(NumCast(this.layoutDoc._width), Doc.NativeWidth(this.layoutDoc)), this._panelWidth) :
- (this.NativeAspect() && this.NativeAspect() < this._panelWidth / this._panelHeight ? this._panelHeight * this.NativeAspect() : this._panelWidth)
+ (this.NativeAspect() && this.NativeAspect() < this._panelWidth / this._panelHeight ? this._panelHeight * this.NativeAspect() : this._panelWidth);
}
@computed get _nativeWidth() { return !this.layoutDoc?._fitWidth ? Doc.NativeWidth(this.layoutDoc) || this._panelWidth : 0; }
@computed get _nativeHeight() { return !this.layoutDoc?._fitWidth ? Doc.NativeHeight(this.layoutDoc) || this._panelHeight : 0; }