diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-07-11 15:03:32 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-07-11 15:09:56 +1000 |
| commit | 776692bc0a5115202774b715bd14d2cd505549dc (patch) | |
| tree | bb81866cddae09b57e648d83b74269d89cabead5 | |
| parent | e77845075eaa813b5c8bf765023e0423f4327780 (diff) | |
Use initial-tree-cache to reduce initial load timeinitial-tree-cache
| -rw-r--r-- | backend/tolData/README.md | 5 | ||||
| -rw-r--r-- | src/App.vue | 24 | ||||
| -rw-r--r-- | src/README.md | 19 | ||||
| -rw-r--r-- | src/initialTrees.json | 1 |
4 files changed, 34 insertions, 15 deletions
diff --git a/backend/tolData/README.md b/backend/tolData/README.md index 75731ae..ba0699d 100644 --- a/backend/tolData/README.md +++ b/backend/tolData/README.md @@ -146,3 +146,8 @@ Some of the scripts use third-party packages: 3. Run genReducedTrees.py, which generates multiple reduced versions of the tree, adding the `nodes_*` and `edges_*` tables, using `nodes` and `names`. Reads from pickedNodes.txt, which lists names of nodes that must be included (1 per line). + +## Other +- The client-side code can use an initial tree cache at + src/initialTrees.json, which should be kept in sync with database + changes. More details in src/README.md. diff --git a/src/App.vue b/src/App.vue index ecf2948..3bbb5cd 100644 --- a/src/App.vue +++ b/src/App.vue @@ -106,6 +106,7 @@ import {arraySum, randWeightedChoice, timeout} from './util'; // Constants const SERVER_WAIT_MSG = 'Loading data'; const PROCESSING_WAIT_MSG = 'Processing'; +import initialTrees from './initialTrees.json'; // Cached server data used to reduce load time // Type representing auto-mode actions type AutoAction = 'move across' | 'move down' | 'move up' | Action; // Function used in auto-mode to reduce action cycles @@ -941,14 +942,19 @@ export default defineComponent({ // Get possible target node from URL let nodeName = (new URL(window.location.href)).searchParams.get('node'); // Query server - let urlParams = new URLSearchParams({type: 'node', tree: this.uiOpts.tree}); - if (nodeName != null){ - urlParams.append('name', nodeName); - urlParams.append('toroot', '1'); - } - let responseObj: {[x: string]: TolNode} = await this.loadFromServer(urlParams); - if (responseObj == null){ - return; + let responseObj: {[x: string]: TolNode}; + if (nodeName == null && initialTrees != null){ // Use pre-stored initial-tree data + responseObj = initialTrees[this.uiOpts.tree as keyof typeof initialTrees]; + } else { + let urlParams = new URLSearchParams({type: 'node', tree: this.uiOpts.tree}); + if (nodeName != null){ + urlParams.append('name', nodeName); + urlParams.append('toroot', '1'); + } + responseObj = await this.loadFromServer(urlParams); + if (responseObj == null){ + return; + } } // Get root node name let rootName = null; @@ -1103,7 +1109,7 @@ export default defineComponent({ } }, }, - created(){ + mounted(){ window.addEventListener('resize', this.onResize); window.addEventListener('keydown', this.onKeyUp); this.initTreeFromServer(); diff --git a/src/README.md b/src/README.md index 5c88b2e..cc10e08 100644 --- a/src/README.md +++ b/src/README.md @@ -14,9 +14,16 @@ - **IconButton.vue**: Simple button component containing an SVG icon. - **SCollapsible.vue**: Simple collapsible-content component. - **icon**: Contains components that display SVG icons. -- **tol.ts**: Holds types for tree-of-life data. -- **layout.ts**: Holds code for laying out tiles. -- **lib.ts**: Holds project-wide globals. -- **util.ts**: Holds utility functions. -- **index.css**: Included by main.ts. Provides Tailwind's CSS classes. -- **env.d.ts**: From Vite's template files. +- **tol.ts**: Holds types for tree-of-life data. +- **layout.ts**: Holds code for laying out tiles. +- **lib.ts**: Holds project-wide globals. +- **util.ts**: Holds utility functions. +- **index.css**: Included by main.ts. Provides Tailwind's CSS classes. +- **initialTrees.json**: Cache of initial tree data from server. Used to reduce load time. + + Holds a map from tree names (trimmed, images, picked) to the result of querying the + backend dev server at `http://localhost:8000/data/?type=node&tree=TREE_NAME`. + + Usage can be disabled by replacing `import initialTrees from ...;` in App.vue with + `const initialTrees = null;`. +- **env.d.ts**: From Vite's template files. diff --git a/src/initialTrees.json b/src/initialTrees.json new file mode 100644 index 0000000..0d622d3 --- /dev/null +++ b/src/initialTrees.json @@ -0,0 +1 @@ +{"trimmed":{"archaea":{"children":["[halobacteria + methanobacteria]","[thermoplasmata + crenarchaeota]","hadesarchaea","lokiarchaeum"],"commonName":"archaeans","imgName":"ott820302.jpg","otolId":"ott996421","pSupport":true,"parent":"cellular organisms","tips":335},"bacteria":{"children":["[salmonella + thermotogae [2]]","buttiauxella","arenicellaceae","armatimonadetes","bd1-5","acidihalobacter prosperus","bacterium","biostraticola","budviciaceae","caldiserica","candidatus blochmannia","candidatus carsonella","cedecea","kluyvera","morganella morganii","orbales","plesiomonas","raoultella","rf3","serratia entomophila","shimwellia","thorselliaceae","yokenella"],"commonName":null,"imgName":"ott3308.jpg","otolId":"ott844192","pSupport":true,"parent":"cellular organisms","tips":7537},"cellular organisms":{"children":["eukaryota","bacteria","archaea"],"commonName":null,"imgName":"ott93302.jpg","otolId":"ott93302","pSupport":false,"parent":null,"tips":343325},"eukaryota":{"children":["opisthokonta","[chloroplastida + amoebozoa]","thecomonadea","centrohelida","collodictyonidae","rigifilida","picozoa","rhodelphis","sarcomastigophora"],"commonName":"eukaryotes","imgName":"ott304358.jpg","otolId":"ott304358","pSupport":false,"parent":"cellular organisms","tips":335453}},"images":{"archaea":{"children":["methanothermobacter","thermococcaceae","halobacteria","archaeoglobi","cenarchaeum symbiosum","crenarchaeota","korarchaeota","thermoplasmata"],"commonName":"archaeans","imgName":"ott820302.jpg","otolId":"ott996421","pSupport":true,"parent":"cellular organisms","tips":16},"bacteria":{"children":["actinobacteria","cyanobacteria/melainabacteria group","streptococcaceae","xanthomonadaceae","mollicutes","anaplasmataceae","comamonadaceae","sphingomonadales","spirochaetales","bradyrhizobiaceae","burkholderia","dickeya","myxococcales","staphylococcus","vibrionaceae","fusobacteriales","neisseriales","paenibacillaceae","ralstonia","shewanella","sinorhizobium/ensifer group","actinobacillus suis","aerococcus urinae","aeromonas hydrophila","agrobacterium rhizogenes","alcanivorax borkumensis","aliidiomarina minuta","alishewanella fetalis","amphibacillus xylanus","azotobacter chroococcum","bacillus clausii","bacillus flexus","bacillus licheniformis","bacillus megaterium","bacillus mycoides","bacillus subtilis","bacteroides fragilis","bartonella","bdellovibrio bacteriovorus","beggiatoa","bergeyella zoohelcum","bordetella bronchiseptica","bordetella parapertussis","bordetella pertussis","buchnera aphidicola","campylobacter jejuni","candidatus brocadia anammoxidans","carboxydocella sporoproducens","carboxydothermus hydrogenoformans","chlamydiales","chlorobiaceae","chromatium","chryseobacterium oleae","chrysiogenes arsenatis","clostridium acetobutylicum","clostridium botulinum","clostridium butyricum","clostridium tetani","clostridium ventriculi","coxiella burnetii","cupriavidus necator","cytophaga","desulfovibrio alaskensis","diplorickettsia massiliensis","elizabethkingia meningoseptica","epilithonimonas","erwinia","erwinia amylovora","erwinia chrysantum","erwinia tracheiphila","fibrobacteres","francisella tularensis","gemmatimonas aurantiaca","halothiobacillus neapolitanus","hyphomicrobium","janthinobacterium lividum","klebsiella oxytoca","klebsiella pneumoniae","lactobacillus casei","lactobacillus delbrueckii","lactobacillus delbrueckii subsp. bulgaricus","lactobacillus delbrueckii subsp. lactis","lactobacillus johnsonii","lactobacillus paracasei","lactobacillus rhamnosus","lactobacillus rhamnosus gg","lactobacillus sakei l45","lactobacillus sakei subsp. carnosus","lactobacillus sakei subsp. sakei","legionella pneumophila","mariprofundus ferrooxydans","mesorhizobium","methylobacterium fujisawaense","methylobacterium jeotgali","methylococcus capsulatus","moraxella catarrhalis","morganella morganii","nitrosomonas","pantoea stewartii","pantoea stewartii subsp. stewartii","pasteuria ramosa","pectobacterium carotovorum","planobacterium","proteobacteria","pseudomonas chloritidismutans","pseudomonas cichorii","pseudomonas fluorescens","pseudomonas marginalis","pseudomonas stutzeri","pseudomonas syringae","pseudomonas syringae pv. actinidiae","pseudomonas syringae pv. persicae","pseudomonas teessidea","raoultella electrica","raoultella planticola","raoultella terrigena","rhizobium","rickettsia rickettsii","salmonella enterica","sar11 clade","serratia marcescens","soonwooa","synergistetes","thermoactinomyces vulgaris","thermus aquaticus","thioploca","thorsellia","turicibacter","veillonella parvula","venenivibrio stagnispumantis","verrucomicrobia","yersinia hibernica"],"commonName":null,"imgName":"ott3308.jpg","otolId":"ott844192","pSupport":true,"parent":"cellular organisms","tips":235},"cellular organisms":{"children":["eukaryota","bacteria","archaea"],"commonName":null,"imgName":"ott93302.jpg","otolId":"ott93302","pSupport":false,"parent":null,"tips":118412},"eukaryota":{"children":["opisthokonta","chloroplastida","sar","rhodophyta","amoebozoa","excavata","haptophyta","thecomonadea","glaucophyta","centrohelida","cryptomonadales"],"commonName":"eukaryotes","imgName":"ott304358.jpg","otolId":"ott304358","pSupport":false,"parent":"cellular organisms","tips":118161}},"picked":{"archaea":{"children":["archaeoglobi","crenarchaeota","halobacteria","methanobacteria","thermococci","thermoplasmata"],"commonName":"archaeans","imgName":"ott820302.jpg","otolId":"ott996421","pSupport":true,"parent":"cellular organisms","tips":6},"bacteria":{"children":["actinobacteria","spirochaetaceae","streptococcus","chlamydiae","chrysiogenetes","clostridium botulinum","clostridium tetani","cyanobacteria","fibrobacteres","legionella","neisseriaceae","proteobacteria","rhizobium","rickettsiaceae","salmonella","staphylococcus","yersinia"],"commonName":null,"imgName":"ott3308.jpg","otolId":"ott844192","pSupport":true,"parent":"cellular organisms","tips":21},"cellular organisms":{"children":["eukaryota","bacteria","archaea"],"commonName":null,"imgName":"ott93302.jpg","otolId":"ott93302","pSupport":false,"parent":null,"tips":2160},"eukaryota":{"children":["opisthokonta","streptophyta","sar","excavata","amoebozoa","centrohelida","haptophyta"],"commonName":"eukaryotes","imgName":"ott304358.jpg","otolId":"ott304358","pSupport":false,"parent":"cellular organisms","tips":2133}}} |
