-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use more granular strategy for caching
- Loading branch information
1 parent
ebd99ae
commit 3975c8b
Showing
6 changed files
with
98 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
app/packages/core/src/components/Sidebar/useOnSidebarSelectionChange.ts
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
app/packages/core/src/components/Sidebar/useShouldReloadSample.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { activeLabelFields } from "@fiftyone/state"; | ||
import { useCallback } from "react"; | ||
import { useRecoilValue } from "recoil"; | ||
|
||
type LookerId = string; | ||
type CachedLabels = Set<string>; | ||
|
||
export const gridActivePathsLUT = new Map<LookerId, CachedLabels>(); | ||
|
||
export const useShouldReloadSampleOnActiveFieldsChange = ({ | ||
modal, | ||
}: { | ||
modal: boolean; | ||
}) => { | ||
const activeLabelFieldsValue = useRecoilValue(activeLabelFields({ modal })); | ||
|
||
const shouldRefresh = useCallback( | ||
(id: string) => { | ||
const thisLookerActiveFields = gridActivePathsLUT.get(id); | ||
const currentActiveLabelFields = new Set(activeLabelFieldsValue); | ||
|
||
if (currentActiveLabelFields.size === 0) { | ||
return false; | ||
} | ||
|
||
// diff the two sets, we only care about net new fields | ||
// if there are no new fields, we don't need to update the tracker | ||
let hasNewFields = false; | ||
|
||
if (thisLookerActiveFields) { | ||
for (const field of currentActiveLabelFields) { | ||
if (!thisLookerActiveFields.has(field)) { | ||
hasNewFields = true; | ||
break; | ||
} | ||
} | ||
} else { | ||
hasNewFields = true; | ||
} | ||
|
||
if (!hasNewFields) { | ||
return false; | ||
} | ||
|
||
gridActivePathsLUT.set( | ||
id, | ||
new Set([ | ||
...(thisLookerActiveFields ?? []), | ||
...currentActiveLabelFields, | ||
]) | ||
); | ||
|
||
return true; | ||
}, | ||
[activeLabelFieldsValue] | ||
); | ||
|
||
return shouldRefresh; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters