fix(cornerstoneCache):Race condition on cache notification (#2900)
This commit is contained in:
parent
9df557831b
commit
06feca1f4a
@ -232,22 +232,22 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const loadViewportData = async () => {
|
const loadViewportData = async () => {
|
||||||
const viewportData = await CornerstoneCacheService.getViewportData(
|
await CornerstoneCacheService.getViewportData(
|
||||||
viewportIndex,
|
viewportIndex,
|
||||||
displaySets,
|
displaySets,
|
||||||
viewportOptions.viewportType,
|
viewportOptions.viewportType,
|
||||||
dataSource,
|
dataSource,
|
||||||
initialImageIndex
|
(viewportDataLoaded) => {
|
||||||
);
|
|
||||||
|
|
||||||
CornerstoneViewportService.setViewportDisplaySets(
|
CornerstoneViewportService.setViewportDisplaySets(
|
||||||
viewportIndex,
|
viewportIndex,
|
||||||
viewportData,
|
viewportDataLoaded,
|
||||||
viewportOptions,
|
viewportOptions,
|
||||||
displaySetOptions
|
displaySetOptions
|
||||||
);
|
);
|
||||||
|
setViewportData(viewportDataLoaded);
|
||||||
setViewportData(viewportData);
|
},
|
||||||
|
initialImageIndex
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
loadViewportData();
|
loadViewportData();
|
||||||
|
|||||||
@ -137,7 +137,7 @@ function ViewportOrientationMarkers({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const imageIndex = imageSliceData.imageIndex;
|
const imageIndex = imageSliceData.imageIndex;
|
||||||
const imageId = viewportData?.imageIds[imageIndex];
|
const imageId = viewportData.imageIds?.[imageIndex];
|
||||||
|
|
||||||
// Workaround for below TODO stub
|
// Workaround for below TODO stub
|
||||||
if (!imageId) {
|
if (!imageId) {
|
||||||
|
|||||||
@ -32,6 +32,8 @@ const EVENTS = {
|
|||||||
VIEWPORT_DATA_CHANGED: 'event::cornerstone::viewportdatachanged',
|
VIEWPORT_DATA_CHANGED: 'event::cornerstone::viewportdatachanged',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type IViewportData = StackData | VolumeData;
|
||||||
|
|
||||||
class CornerstoneCacheService {
|
class CornerstoneCacheService {
|
||||||
stackImageIds: Map<string, string[]> = new Map();
|
stackImageIds: Map<string, string[]> = new Map();
|
||||||
volumeImageIds: Map<string, string[]> = new Map();
|
volumeImageIds: Map<string, string[]> = new Map();
|
||||||
@ -57,10 +59,11 @@ class CornerstoneCacheService {
|
|||||||
displaySets: unknown[],
|
displaySets: unknown[],
|
||||||
viewportType: string,
|
viewportType: string,
|
||||||
dataSource: unknown,
|
dataSource: unknown,
|
||||||
|
callback: (val: IViewportData) => unknown,
|
||||||
initialImageIndex?: number
|
initialImageIndex?: number
|
||||||
): Promise<StackData | VolumeData> {
|
): Promise<StackData | VolumeData> {
|
||||||
const cs3DViewportType = getCornerstoneViewportType(viewportType);
|
const cs3DViewportType = getCornerstoneViewportType(viewportType);
|
||||||
let viewportData: StackData | VolumeData;
|
let viewportData: IViewportData;
|
||||||
|
|
||||||
if (cs3DViewportType === Enums.ViewportType.STACK) {
|
if (cs3DViewportType === Enums.ViewportType.STACK) {
|
||||||
viewportData = await this._getStackViewportData(
|
viewportData = await this._getStackViewportData(
|
||||||
@ -76,6 +79,8 @@ class CornerstoneCacheService {
|
|||||||
|
|
||||||
viewportData.viewportType = cs3DViewportType;
|
viewportData.viewportType = cs3DViewportType;
|
||||||
|
|
||||||
|
await callback(viewportData);
|
||||||
|
|
||||||
this._broadcastEvent(this.EVENTS.VIEWPORT_DATA_CHANGED, {
|
this._broadcastEvent(this.EVENTS.VIEWPORT_DATA_CHANGED, {
|
||||||
viewportData,
|
viewportData,
|
||||||
viewportIndex,
|
viewportIndex,
|
||||||
@ -83,7 +88,6 @@ class CornerstoneCacheService {
|
|||||||
|
|
||||||
return viewportData;
|
return viewportData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async invalidateViewportData(
|
public async invalidateViewportData(
|
||||||
viewportData: VolumeData,
|
viewportData: VolumeData,
|
||||||
invalidatedDisplaySetInstanceUID: string,
|
invalidatedDisplaySetInstanceUID: string,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user