Skip to content

Commit 1eea8e7

Browse files
Fix infinite requests in alignment modal (#8978)
This PR avoids using new object identities in certain accessors. This also fixes that the "Create Annotation" button was constantly rerendered on mouse move. ### URL of deployed dev instance (used for testing): - https://___.webknossos.xyz ### Steps to test: - I applied this local diff: ``` diff --git i/frontend/javascripts/viewer/view/action_bar_view.tsx w/frontend/javascripts/viewer/view/action_bar_view.tsx index 70c3e06..4406989a26 100644 --- i/frontend/javascripts/viewer/view/action_bar_view.tsx +++ w/frontend/javascripts/viewer/view/action_bar_view.tsx @@ -305,7 +305,7 @@ class ActionBarView extends React.PureComponent<Props, State> { key="ai-job-button" onClick={() => Store.dispatch(setAIJobModalStateAction(APIJobType.INFER_NEURONS))} style={{ marginLeft: 12, pointerEvents: "auto" }} - disabled={disabled} + // disabled={disabled} title={tooltipText} icon={<i className="fas fa-magic" />} > @@ -370,9 +370,7 @@ class ActionBarView extends React.PureComponent<Props, State> { <DatasetPositionAndRotationView /> <AdditionalCoordinatesInputView /> <ModesView /> - {getIsAIAnalysisEnabled() && isAdminOrDatasetManager - ? this.renderStartAIJobButton(shouldDisableAIJobButton, tooltip) - : null} + {this.renderStartAIJobButton(shouldDisableAIJobButton, tooltip)} {isViewMode ? this.renderStartTracingButton() : null} {constants.MODES_PLANE.indexOf(viewMode) > -1 ? <ToolbarView /> : null} </div> ``` and opened the AI modal (without no worker setup). prior to the PR, the infinite requests to the credit cost calculation could be seen. with this PR, it's fixed. ### Issues: - fixes https://scm.slack.com/archives/C5AKLAV0B/p1759755474212069 ------ (Please delete unneeded items, merge only when none are left open) - [x] Added changelog entry (create a `$PR_NUMBER.md` file in `unreleased_changes` or use `./tools/create-changelog-entry.py`) - [ ] Added migration guide entry if applicable (edit the same file as for the changelog) - [ ] Updated [documentation](../blob/master/docs) if applicable - [ ] Adapted [wk-libs python client](https://github.com/scalableminds/webknossos-libs/tree/master/webknossos/webknossos/client) if relevant API parts change - [ ] Removed dev-only changes like prints and application.conf edits - [ ] Considered [common edge cases](../blob/master/.github/common_edge_cases.md) - [ ] Needs datastore update after deployment --------- Co-authored-by: MichaelBuessemeyer <[email protected]>
1 parent b2b40dd commit 1eea8e7

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

frontend/javascripts/viewer/model/accessors/dataset_accessor.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type {
2929
import BoundingBox from "../bucket_data_handling/bounding_box";
3030
import { getSupportedValueRangeForElementClass } from "../bucket_data_handling/data_rendering_logic";
3131
import { MagInfo, convertToDenseMag } from "../helpers/mag_info";
32+
import { reuseInstanceOnEquality } from "./accessor_helpers";
3233

3334
function _getMagInfo(magnifications: Array<Vector3>): MagInfo {
3435
return new MagInfo(magnifications);
@@ -456,7 +457,7 @@ export function hasVisibleUint64Segmentation(state: WebknossosState) {
456457
return segmentationLayer ? segmentationLayer.elementClass === "uint64" : false;
457458
}
458459

459-
export function getVisibleSegmentationLayers(state: WebknossosState): Array<APISegmentationLayer> {
460+
function _getVisibleSegmentationLayers(state: WebknossosState): Array<APISegmentationLayer> {
460461
const { datasetConfiguration } = state;
461462
const { viewMode } = state.temporaryConfiguration;
462463
const segmentationLayers = getSegmentationLayers(state.dataset);
@@ -466,6 +467,8 @@ export function getVisibleSegmentationLayers(state: WebknossosState): Array<APIS
466467
return visibleSegmentationLayers;
467468
}
468469

470+
export const getVisibleSegmentationLayers = reuseInstanceOnEquality(_getVisibleSegmentationLayers);
471+
469472
export function getSegmentationLayerWithMappingSupport(
470473
state: WebknossosState,
471474
): APISegmentationLayer | null | undefined {
@@ -501,7 +504,7 @@ export function getFirstSegmentationLayer(
501504

502505
return null;
503506
}
504-
export function getSegmentationLayers(
507+
export function _getSegmentationLayers(
505508
dataset: APIMaybeUnimportedDataset,
506509
): Array<APISegmentationLayer> {
507510
if (!dataset.isActive) {
@@ -513,6 +516,9 @@ export function getSegmentationLayers(
513516
) as APISegmentationLayer[];
514517
return segmentationLayers;
515518
}
519+
520+
export const getSegmentationLayers = memoizeOne(_getSegmentationLayers);
521+
516522
export function hasSegmentation(dataset: APIDataset): boolean {
517523
return getSegmentationLayers(dataset).length > 0;
518524
}
@@ -530,10 +536,12 @@ export function doesSupportVolumeWithFallback(
530536

531537
return true;
532538
}
533-
export function getColorLayers(dataset: APIDataset): Array<DataLayerType> {
539+
function _getColorLayers(dataset: APIDataset): Array<DataLayerType> {
534540
return dataset.dataSource.dataLayers.filter((dataLayer) => isColorLayer(dataset, dataLayer.name));
535541
}
536-
export function getEnabledLayers(
542+
export const getColorLayers = memoizeOne(_getColorLayers);
543+
544+
function _getEnabledLayers(
537545
dataset: APIDataset,
538546
datasetConfiguration: DatasetConfiguration,
539547
options: {
@@ -553,13 +561,13 @@ export function getEnabledLayers(
553561
});
554562
}
555563

556-
export function getEnabledColorLayers(
557-
dataset: APIDataset,
558-
datasetConfiguration: DatasetConfiguration,
559-
) {
564+
export const getEnabledLayers = memoizeOne(_getEnabledLayers);
565+
566+
function _getEnabledColorLayers(dataset: APIDataset, datasetConfiguration: DatasetConfiguration) {
560567
const enabledLayers = getEnabledLayers(dataset, datasetConfiguration);
561568
return enabledLayers.filter((layer) => isColorLayer(dataset, layer.name));
562569
}
570+
export const getEnabledColorLayers = memoizeOne(_getEnabledColorLayers);
563571

564572
export function getThumbnailURL(dataset: APIDataset): string {
565573
const layers = dataset.dataSource.dataLayers;

unreleased_changes/8978.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Fixed
2+
- Fixed that WEBKNOSSOS sent too many requests when the alignment analysis dialog was open.

0 commit comments

Comments
 (0)