Skip to content

Commit

Permalink
fix(search): add breakpoints to prevent race conditions for counts (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored Dec 14, 2023
1 parent 6255c7f commit 5344477
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions frontend/src/lib/components/CommandBar/searchBarLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,21 @@ export const searchBarLogic = kea<searchBarLogicType>([

actions.reportCommandBarSearch(values.searchQuery.length)

let response
if (clickhouseTabs.includes(values.activeTab)) {
// prevent race conditions when switching tabs quickly
return values.rawSearchResponse
response = values.rawSearchResponse
} else if (values.activeTab === Tab.All) {
return await api.search.list({ q: values.searchQuery })
response = await api.search.list({ q: values.searchQuery })
} else {
return await api.search.list({
response = await api.search.list({
q: values.searchQuery,
entities: [values.activeTab.toLowerCase() as SearchableEntity],
})
}

breakpoint()
return response
},
},
],
Expand All @@ -93,7 +97,9 @@ export const searchBarLogic = kea<searchBarLogicType>([
{
loadPersonsResponse: async (_, breakpoint) => {
await breakpoint(DEBOUNCE_MS)
return await api.persons.list({ search: values.searchQuery })
const response = await api.persons.list({ search: values.searchQuery })
breakpoint()
return response
},
},
],
Expand All @@ -102,7 +108,9 @@ export const searchBarLogic = kea<searchBarLogicType>([
{
loadGroup0Response: async (_, breakpoint) => {
await breakpoint(DEBOUNCE_MS)
return await api.groups.list({ group_type_index: 0, search: values.searchQuery })
const response = await api.groups.list({ group_type_index: 0, search: values.searchQuery })
breakpoint()
return response
},
},
],
Expand All @@ -111,7 +119,9 @@ export const searchBarLogic = kea<searchBarLogicType>([
{
loadGroup1Response: async (_, breakpoint) => {
await breakpoint(DEBOUNCE_MS)
return await api.groups.list({ group_type_index: 1, search: values.searchQuery })
const response = await api.groups.list({ group_type_index: 1, search: values.searchQuery })
breakpoint()
return response
},
},
],
Expand All @@ -120,7 +130,9 @@ export const searchBarLogic = kea<searchBarLogicType>([
{
loadGroup2Response: async (_, breakpoint) => {
await breakpoint(DEBOUNCE_MS)
return await api.groups.list({ group_type_index: 2, search: values.searchQuery })
const response = await api.groups.list({ group_type_index: 2, search: values.searchQuery })
breakpoint()
return response
},
},
],
Expand All @@ -129,7 +141,9 @@ export const searchBarLogic = kea<searchBarLogicType>([
{
loadGroup3Response: async (_, breakpoint) => {
await breakpoint(DEBOUNCE_MS)
return await api.groups.list({ group_type_index: 3, search: values.searchQuery })
const response = await api.groups.list({ group_type_index: 3, search: values.searchQuery })
breakpoint()
return response
},
},
],
Expand All @@ -138,7 +152,9 @@ export const searchBarLogic = kea<searchBarLogicType>([
{
loadGroup4Response: async (_, breakpoint) => {
await breakpoint(DEBOUNCE_MS)
return await api.groups.list({ group_type_index: 4, search: values.searchQuery })
const response = await api.groups.list({ group_type_index: 4, search: values.searchQuery })
breakpoint()
return response
},
},
],
Expand Down

0 comments on commit 5344477

Please sign in to comment.