Skip to content

Commit

Permalink
check for l2cache existing is now cached and only checked when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Nov 21, 2023
1 parent 19d14de commit 8ae7918
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/neuroglancer/datasource/graphene/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ class GrapheneGraphServerInterface {
class GrapheneGraphSource extends SegmentationGraphSource {
private connections = new Set<GraphConnection>();
public graphServer: GrapheneGraphServerInterface;
private l2CacheAvailable: boolean|undefined = undefined;

constructor(
public info: GrapheneMultiscaleVolumeInfo,
Expand All @@ -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);
}
Expand All @@ -1581,14 +1598,8 @@ class GrapheneGraphSource extends SegmentationGraphSource {
first: SegmentSelection, second: SegmentSelection, precisionMode: boolean,
annotationToNanometers: Float64Array): Promise<number[][]> {
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);
Expand Down

0 comments on commit 8ae7918

Please sign in to comment.