Skip to content

Commit

Permalink
fix(web): skip cache feature for data has updateInterval (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice authored Jul 4, 2023
1 parent 6d0ab3e commit 38489c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
22 changes: 11 additions & 11 deletions web/src/beta/lib/core/engines/Cesium/Feature/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,20 @@ export default function Feature({
const areAllDisplayTypeNoFeature =
Array.isArray(displayType) &&
displayType.every(k => components[k][1].noFeature && !components[k][1].noLayer);
const cacheable = !data?.updateInterval;

const cachedRenderComponent = (
k: keyof AppearanceTypes,
f?: ComputedFeature,
): JSX.Element | null => {
const renderComponent = (k: keyof AppearanceTypes, f?: ComputedFeature): JSX.Element | null => {
const componentId = generateIDWithMD5(
`${layer.id}_${f?.id ?? ""}_${k}_${isHidden}_${data?.url ?? ""}_${
JSON.stringify(f?.[k]) ?? ""
}`,
);

const cachedComponent = CACHED_COMPONENTS.get(componentId);
if (cachedComponent) {
return cachedComponent;
if (cacheable) {
const cachedComponent = CACHED_COMPONENTS.get(componentId);
if (cacheable && cachedComponent) {
return cachedComponent;
}
}

try {
Expand Down Expand Up @@ -138,7 +138,9 @@ export default function Feature({
);

// Cache the component output
CACHED_COMPONENTS.set(componentId, component);
if (cacheable) {
CACHED_COMPONENTS.set(componentId, component);
}

return component;
} catch (e) {
Expand Down Expand Up @@ -182,9 +184,7 @@ export default function Feature({
<>
{cachedNoFeatureComponents ||
[undefined, ...layer.features].flatMap(f =>
(Object.keys(components) as (keyof AppearanceTypes)[]).map(k =>
cachedRenderComponent(k, f),
),
(Object.keys(components) as (keyof AppearanceTypes)[]).map(k => renderComponent(k, f)),
)}
</>
);
Expand Down
23 changes: 12 additions & 11 deletions web/src/classic/core/engines/Cesium/Feature/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,21 @@ export default function Feature({
const areAllDisplayTypeNoFeature =
Array.isArray(displayType) &&
displayType.every(k => components[k][1].noFeature && !components[k][1].noLayer);
const cacheable = !data?.updateInterval;

const cachedRenderComponent = (
k: keyof AppearanceTypes,
f?: ComputedFeature,
): JSX.Element | null => {
const renderComponent = (k: keyof AppearanceTypes, f?: ComputedFeature): JSX.Element | null => {
const componentId = generateIDWithMD5(
`${layer.id}_${f?.id ?? ""}_${k}_${isHidden}_${data?.url ?? ""}_${
JSON.stringify(f?.[k]) ?? ""
}`,
);

const cachedComponent = CACHED_COMPONENTS.get(componentId);
if (cachedComponent) {
return cachedComponent;
if (cacheable) {
const cachedComponent = CACHED_COMPONENTS.get(componentId);

if (cachedComponent) {
return cachedComponent;
}
}

try {
Expand Down Expand Up @@ -138,7 +139,9 @@ export default function Feature({
);

// Cache the component output
CACHED_COMPONENTS.set(componentId, component);
if (cacheable) {
CACHED_COMPONENTS.set(componentId, component);
}

return component;
} catch (e) {
Expand Down Expand Up @@ -182,9 +185,7 @@ export default function Feature({
<>
{cachedNoFeatureComponents ||
[undefined, ...layer.features].flatMap(f =>
(Object.keys(components) as (keyof AppearanceTypes)[]).map(k =>
cachedRenderComponent(k, f),
),
(Object.keys(components) as (keyof AppearanceTypes)[]).map(k => renderComponent(k, f)),
)}
</>
);
Expand Down

0 comments on commit 38489c3

Please sign in to comment.