diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-07-08 14:50:21 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-07-08 15:00:32 +1000 |
| commit | 4e2830b6986aef2486d12c20ffc37d4bb595ced4 (patch) | |
| tree | 22d1daa307b72da75634200c5faea221ec44c742 | |
| parent | d84a2dab11aa23d56c3213008424872e1a011279 (diff) | |
Send activeRoot to server, for reducing toroot response sizes
| -rwxr-xr-x | backend/cgi-bin/data.py | 29 | ||||
| -rw-r--r-- | src/App.vue | 7 | ||||
| -rw-r--r-- | src/components/SearchModal.vue | 3 |
3 files changed, 27 insertions, 12 deletions
diff --git a/backend/cgi-bin/data.py b/backend/cgi-bin/data.py index 1334dfc..b02cfc9 100755 --- a/backend/cgi-bin/data.py +++ b/backend/cgi-bin/data.py @@ -22,8 +22,8 @@ Query parameters: If 'node', reply with a name-to-TolNode map, describing the named node and it's children. If 'sugg', reply with a SearchSuggResponse, describing search suggestions for the possibly-partial name. If 'info', reply with an InfoResponse, describing the named node. -- toroot: Used with type=node, and causes inclusion of nodes upward to the root, and their children. - If specified, the value should be 'true'. +- toroot: Used with type=node, and causes inclusion of ancestors, and their children. + The value names a node whose ancestors need not be included. - limit: Used with type=sugg to specify the max number of suggestions. - tree: Specifies which tree should be used. May be 'trimmed', 'images', or 'picked', corresponding to the @@ -88,7 +88,7 @@ def lookupNodes(names, tree, dbCur): " For a set of node names, returns a name-to-TolNode map that describes those nodes " # Get node info nameToNodes = {} - tblSuffix = "t" if tree == "trimmed" else "i" if tree == "images" else "p" + tblSuffix = getTableSuffix(tree) nodesTable = f"nodes_{tblSuffix}" edgesTable = f"edges_{tblSuffix}" queryParamStr = ",".join(["?"] * len(names)) @@ -143,8 +143,7 @@ def lookupSuggs(searchStr, suggLimit, tree, dbCur): hasMore = False # Get node names and alt-names query1, query2 = (None, None) - tblSuffix = "t" if tree == "trimmed" else "i" if tree == "images" else "p" - nodesTable = f"nodes_{tblSuffix}" + nodesTable = f"nodes_{getTableSuffix(tree)}" query1 = f"SELECT DISTINCT name FROM {nodesTable}" \ f" WHERE name LIKE ? AND name NOT LIKE '[%' ORDER BY length(name) LIMIT ?" query2 = f"SELECT DISTINCT alt_name, names.name FROM" \ @@ -254,8 +253,8 @@ def handleReq(dbCur): return # Get data of requested type if reqType == "node": - toroot = "toroot" in queryDict and queryDict["toroot"][0] == "true" - if not toroot: + toroot = queryDict["toroot"][0] if "toroot" in queryDict else None + if toroot == None: tolNodes = lookupNodes([name], tree, dbCur) if len(tolNodes) > 0: tolNode = tolNodes[name] @@ -264,6 +263,18 @@ def handleReq(dbCur): respondJson(childNodeObjs) return else: + # Get ancestors to skip inclusion of + nodesToSkip = set() + nodeName = toroot + edgesTable = f"edges_{getTableSuffix(tree)}" + while True: + row = dbCur.execute(f"SELECT parent FROM {edgesTable} WHERE child = ?", (nodeName,)).fetchone() + if row == None: + break + parent = row[0] + nodesToSkip.add(parent) + nodeName = parent + # results = {} ranOnce = False while True: @@ -288,7 +299,7 @@ def handleReq(dbCur): childNodeObjs = lookupNodes(childNamesToAdd, tree, dbCur) results.update(childNodeObjs) # Check if root - if tolNode.parent == None: + if tolNode.parent == None or tolNode.parent in nodesToSkip: respondJson(results) return else: @@ -315,6 +326,8 @@ def handleReq(dbCur): return # On failure, provide empty response respondJson(None) +def getTableSuffix(tree): + return "t" if tree == "trimmed" else "i" if tree == "images" else "p" # Open db dbCon = sqlite3.connect(dbFile) diff --git a/src/App.vue b/src/App.vue index 434eb08..e379a1d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -49,7 +49,8 @@ </div> <!-- Modals --> <transition name="fade"> - <search-modal v-if="searchOpen" :tolMap="tolMap" :lytMap="layoutMap" :lytOpts="lytOpts" :uiOpts="uiOpts" + <search-modal v-if="searchOpen" + :tolMap="tolMap" :lytMap="layoutMap" :activeRoot="activeRoot" :lytOpts="lytOpts" :uiOpts="uiOpts" @close="onSearchClose" @search="onSearch" @info-click="onInfoClick" @setting-chg="onSettingChg" @net-wait="primeLoadInd('Loading data')" @net-get="endLoadInd" class="z-10" ref="searchModal"/> </transition> @@ -542,7 +543,7 @@ export default defineComponent({ layoutNode.addDescendantChain(nodesToAdd, this.tolMap, this.layoutMap); // Expand-to-view on target-node's parent targetNode = this.layoutMap.get(name); - if (targetNode.parent != this.activeRoot){ + if (targetNode!.parent != this.activeRoot){ await this.onLeafClickHeld(targetNode!.parent!, true); } else { await this.onLeafClick(targetNode!.parent!, true); @@ -864,7 +865,7 @@ export default defineComponent({ let urlParams = new URLSearchParams({type: 'node', tree: this.uiOpts.tree}); if (nodeName != null){ urlParams.append('name', nodeName); - urlParams.append('toroot', 'true'); + urlParams.append('toroot', this.activeRoot.name); } let responseObj: {[x: string]: TolNode} = await this.loadFromServer(urlParams); if (responseObj == null){ diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue index de6bc75..990312a 100644 --- a/src/components/SearchModal.vue +++ b/src/components/SearchModal.vue @@ -43,6 +43,7 @@ import {queryServer, SearchSugg, SearchSuggResponse, UiOptions} from '../lib'; export default defineComponent({ props: { lytMap: {type: Object as PropType<LayoutMap>, required: true}, // Used to check if a searched-for node exists + activeRoot: {type: Object as PropType<LayoutNode>, required: true}, // Sent to server to reduce response size tolMap: {type: Object as PropType<TolMap>, required: true}, // Upon a search response, gets new nodes added lytOpts: {type: Object as PropType<LayoutOptions>, required: true}, uiOpts: {type: Object as PropType<UiOptions>, required: true}, @@ -205,7 +206,7 @@ export default defineComponent({ let urlParams = new URLSearchParams({ type: 'node', name: tolNodeName, - toroot: 'true', + toroot: this.activeRoot.name, tree: this.uiOpts.tree, }); this.$emit('net-wait'); // Allows the parent component to show a loading-indicator |
