Skip to content

Commit

Permalink
fix(persons): bypass cache on the persons page (#22503)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored May 24, 2024
1 parent 08e0480 commit bbd95a0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
26 changes: 22 additions & 4 deletions frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export interface DataNodeLogicProps {
cachedResults?: AnyResponseType
/** Disabled data fetching and only allow cached results. */
doNotLoad?: boolean
/** Queries always get refreshed. */
alwaysRefresh?: boolean
/** Callback when data is successfully loader or provided from cache. */
onData?: (data: Record<string, unknown> | null | undefined) => void
/** Load priority. Higher priority (smaller number) queries will be loaded first. */
Expand Down Expand Up @@ -160,7 +162,8 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
{
setResponse: (response) => response,
clearResponse: () => null,
loadData: async ({ refresh, queryId }, breakpoint) => {
loadData: async ({ refresh: refreshArg, queryId }, breakpoint) => {
const refresh = props.alwaysRefresh || refreshArg
if (props.doNotLoad) {
return props.cachedResults
}
Expand Down Expand Up @@ -245,7 +248,12 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
}
if (isEventsQuery(props.query) && values.newQuery) {
const now = performance.now()
const newResponse = (await query(addModifiers(values.newQuery, props.modifiers))) ?? null
const newResponse =
(await query(
addModifiers(values.newQuery, props.modifiers),
undefined,
props.alwaysRefresh
)) ?? null
actions.setElapsedTime(performance.now() - now)
if (newResponse?.results) {
actions.highlightRows(newResponse?.results)
Expand All @@ -269,7 +277,12 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
// TODO: unify when we use the same backend endpoint for both
const now = performance.now()
if (isEventsQuery(props.query) || isActorsQuery(props.query)) {
const newResponse = (await query(addModifiers(values.nextQuery, props.modifiers))) ?? null
const newResponse =
(await query(
addModifiers(values.nextQuery, props.modifiers),
undefined,
props.alwaysRefresh
)) ?? null
actions.setElapsedTime(performance.now() - now)
const queryResponse = values.response as EventsQueryResponse | ActorsQueryResponse
return {
Expand All @@ -278,7 +291,12 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
hasMore: newResponse?.hasMore,
}
} else if (isPersonsNode(props.query)) {
const newResponse = (await query(addModifiers(values.nextQuery, props.modifiers))) ?? null
const newResponse =
(await query(
addModifiers(values.nextQuery, props.modifiers),
undefined,
props.alwaysRefresh
)) ?? null
actions.setElapsedTime(performance.now() - now)
if (Array.isArray(values.response)) {
// help typescript by asserting we can't have an array here
Expand Down
1 change: 1 addition & 0 deletions frontend/src/queries/nodes/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults }
key: vizKey,
cachedResults: cachedResults,
dataNodeCollectionId: context?.insightProps?.dataNodeCollectionId || dataKey,
alwaysRefresh: context?.alwaysRefresh,
}
const builtDataNodeLogic = dataNodeLogic(dataNodeLogicProps)

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/queries/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface QueryContext {
rowProps?: (record: unknown) => Omit<HTMLProps<HTMLTableRowElement>, 'key'>
/** chart-specific rendering context **/
chartRenderingMetadata?: ChartRenderingMetadata
/** Wether queries should always be refreshed. */
alwaysRefresh?: boolean
}

/** Pass custom rendering metadata to specific kinds of charts **/
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/cohorts/CohortEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export function CohortEdit({ id }: CohortLogicProps): JSX.Element {
minutes.
</div>
) : (
<Query query={query} setQuery={setQuery} />
<Query query={query} setQuery={setQuery} context={{ alwaysRefresh: true }} />
)}
</div>
</>
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/scenes/groups/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ export function Group(): JSX.Element {
key: PersonsTabType.EVENTS,
label: <span data-attr="groups-events-tab">Events</span>,
content: groupEventsQuery ? (
<Query query={groupEventsQuery} setQuery={setGroupEventsQuery} />
<Query
query={groupEventsQuery}
setQuery={setGroupEventsQuery}
context={{ alwaysRefresh: true }}
/>
) : (
<Spinner />
),
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/persons-management/tabs/Persons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function Persons(): JSX.Element {

return (
<>
<Query query={query} setQuery={setQuery} />
<Query query={query} setQuery={setQuery} context={{ alwaysRefresh: true }} />
</>
)
}

0 comments on commit bbd95a0

Please sign in to comment.