From 8ae791860c0c204ef32df31238e39beed1875d10 Mon Sep 17 00:00:00 2001 From: Chris Jordan Date: Tue, 21 Nov 2023 17:42:48 -0500 Subject: [PATCH] check for l2cache existing is now cached and only checked when necessary --- .../datasource/graphene/frontend.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/neuroglancer/datasource/graphene/frontend.ts b/src/neuroglancer/datasource/graphene/frontend.ts index 6310bc360..07e9e7707 100644 --- a/src/neuroglancer/datasource/graphene/frontend.ts +++ b/src/neuroglancer/datasource/graphene/frontend.ts @@ -1547,6 +1547,7 @@ class GrapheneGraphServerInterface { class GrapheneGraphSource extends SegmentationGraphSource { private connections = new Set(); public graphServer: GrapheneGraphServerInterface; + private l2CacheAvailable: boolean|undefined = undefined; constructor( public info: GrapheneMultiscaleVolumeInfo, @@ -1573,6 +1574,22 @@ class GrapheneGraphSource extends SegmentationGraphSource { VisibleSegmentEquivalencePolicy.NONREPRESENTATIVE_EXCLUDED; } + async isL2CacheUrlAvailable() { + if (this.l2CacheAvailable !== undefined) { + return this.l2CacheAvailable; + } + try { + const {l2CacheUrl, table} = this.info.app; + const tableMapping = await cancellableFetchSpecialOk( + undefined, `${l2CacheUrl}/table_mapping`, {}, responseJson); + this.l2CacheAvailable = !!(tableMapping && tableMapping[table]); + return this.l2CacheAvailable; + } catch (e) { + console.error('e', e); + return false; + } + } + getRoot(segment: Uint64) { return this.graphServer.getRoot(segment); } @@ -1581,14 +1598,8 @@ class GrapheneGraphSource extends SegmentationGraphSource { first: SegmentSelection, second: SegmentSelection, precisionMode: boolean, annotationToNanometers: Float64Array): Promise { const {l2CacheUrl, table} = this.info.app; - let l2CacheAvailable = false; - try { - const tableMapping = await cancellableFetchSpecialOk( - undefined, `${l2CacheUrl}/table_mapping`, {}, responseJson); - l2CacheAvailable = tableMapping && tableMapping[table]; - } catch (e) { - console.error('e', e); - } + const l2CacheAvailable = precisionMode && + await this.isL2CacheUrlAvailable(); // don't check if available if we don't need it let {centroids, l2_path} = await this.graphServer.findPath( selectionInNanometers(first, annotationToNanometers), selectionInNanometers(second, annotationToNanometers), precisionMode && !l2CacheAvailable);