From 5315be00bd7afb3b01a14cf947fa78fba902007d Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 22 Oct 2024 09:31:55 -0400 Subject: [PATCH] Reduce loading geojs when switching views in Girder This checks if geojs is already in memory and doesn't replace it with itself --- CHANGELOG.md | 1 + .../web_client/views/imageViewerWidget/geojs.js | 12 +++++++----- .../test_girder/web_client_specs/imageViewerSpec.js | 6 +++++- .../web_client_specs/annotationListSpec.js | 6 +++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66e90db3c..749b4f036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Speed up recursive item lists ([#1694](../../pull/1694)) - Better handle images with signed pixel data ([#1695](../../pull/1695)) +- Reduce loading geojs when switching views in Girder ([#1699](../../pull/1699)) ## 1.30.1 diff --git a/girder/girder_large_image/web_client/views/imageViewerWidget/geojs.js b/girder/girder_large_image/web_client/views/imageViewerWidget/geojs.js index c009f0ba2..69712427d 100644 --- a/girder/girder_large_image/web_client/views/imageViewerWidget/geojs.js +++ b/girder/girder_large_image/web_client/views/imageViewerWidget/geojs.js @@ -45,11 +45,13 @@ var GeojsImageViewerWidget = ImageViewerWidget.extend({ } return this; }), - $.ajax({ // like $.getScript, but allow caching - url: root + '/plugins/large_image/extra/geojs.js' + (BUILD_TIMESTAMP ? '?_=' + BUILD_TIMESTAMP : ''), - dataType: 'script', - cache: true - })) + !window.geo + ? $.ajax({ // like $.getScript, but allow caching + url: root + '/plugins/large_image/extra/geojs.js' + (BUILD_TIMESTAMP ? '?_=' + BUILD_TIMESTAMP : ''), + dataType: 'script', + cache: true + }) + : true) .done(() => { this.trigger('g:beforeFirstRender', this); this.render(); diff --git a/girder/test_girder/web_client_specs/imageViewerSpec.js b/girder/test_girder/web_client_specs/imageViewerSpec.js index 5d56bf3fb..3d289cf47 100644 --- a/girder/test_girder/web_client_specs/imageViewerSpec.js +++ b/girder/test_girder/web_client_specs/imageViewerSpec.js @@ -11,7 +11,11 @@ $(function () { var GeojsViewer = girder.plugins.large_image.views.imageViewerWidget.geojs; girder.utilities.PluginUtils.wrap(GeojsViewer, 'initialize', function (initialize) { this.once('g:beforeFirstRender', function () { - window.geo.util.mockWebglRenderer(); + try { + window.geo.util.mockWebglRenderer(); + } catch (err) { + // if this is already mocked, do nothing. + } window.geo.webgl.webglRenderer._maxTextureSize = 256; }); initialize.apply(this, _.rest(arguments)); diff --git a/girder_annotation/test_annotation/web_client_specs/annotationListSpec.js b/girder_annotation/test_annotation/web_client_specs/annotationListSpec.js index bdf926be5..db2bc6a34 100644 --- a/girder_annotation/test_annotation/web_client_specs/annotationListSpec.js +++ b/girder_annotation/test_annotation/web_client_specs/annotationListSpec.js @@ -39,7 +39,11 @@ describe('AnnotationListWidget', function () { }; this.once('g:beforeFirstRender', function () { - window.geo.util.mockWebglRenderer(); + try { + window.geo.util.mockWebglRenderer(); + } catch (err) { + // if this is already mocked, do nothing. + } }); initialize.apply(this, _.rest(arguments)); });