-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cache-cell-results): added cell result caching to reduce cell co…
…nfiguration querying on loads (#18581)
- Loading branch information
Showing
10 changed files
with
143 additions
and
24 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
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,33 @@ | ||
export type Action = | ||
| ReturnType<typeof resetCachedQueryResults> | ||
| ReturnType<typeof setQueryResultsByQueryID> | ||
|
||
// Hashing function found here: | ||
// https://jsperf.com/hashcodelordvlad | ||
// Through this thread: | ||
// https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript | ||
export const hashCode = (queryText: string): string => { | ||
let hash = 0, | ||
char | ||
if (!queryText) { | ||
return `${hash}` | ||
} | ||
for (let i = 0; i < queryText.length; i++) { | ||
char = queryText.charCodeAt(i) | ||
hash = (hash << 5) - hash + char | ||
hash |= 0 // Convert to 32bit integer | ||
} | ||
return `${hash}` | ||
} | ||
|
||
export const setQueryResultsByQueryID = (queryID: string, files: string[]) => | ||
({ | ||
type: 'SET_QUERY_RESULTS_BY_QUERY', | ||
queryID, | ||
files, | ||
} as const) | ||
|
||
export const resetCachedQueryResults = () => | ||
({ | ||
type: 'RESET_CACHED_QUERY_RESULTS', | ||
} as const) |
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,33 @@ | ||
// Libraries | ||
import {produce} from 'immer' | ||
|
||
// Actions | ||
import {Action} from 'src/queryCache/actions' | ||
|
||
export interface QueryCacheState { | ||
queryResultsByQueryID: {[queryID: string]: string[]} | ||
} | ||
|
||
export const initialState: QueryCacheState = { | ||
queryResultsByQueryID: {}, | ||
} | ||
|
||
export const queryCacheReducer = ( | ||
state: QueryCacheState = initialState, | ||
action: Action | ||
): QueryCacheState => { | ||
switch (action.type) { | ||
case 'SET_QUERY_RESULTS_BY_QUERY': { | ||
return produce(state, draftState => { | ||
const {queryID, files} = action | ||
draftState.queryResultsByQueryID[queryID] = files | ||
}) | ||
} | ||
|
||
case 'RESET_CACHED_QUERY_RESULTS': { | ||
return {queryResultsByQueryID: {}} | ||
} | ||
} | ||
|
||
return state | ||
} |
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
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