The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Replace the custom-homepage cache patch with tag invalidation (#79867)
Frasera9ad0ee017cb
diff --git a/frontend/src/metabase/api/dashboard.ts b/frontend/src/metabase/api/dashboard.tsindex 1abf0317ff1..73d01652399 100644--- a/frontend/src/metabase/api/dashboard.ts+++ b/frontend/src/metabase/api/dashboard.ts@@ -40,9 +40,7 @@ import {provideValidDashboardFilterFieldTags,tag,} from "./tags";-import { userApi } from "./user";import { hydrateMetadataStore } from "./utils/hydrate-metadata-store";-import { handleQueryFulfilled } from "./utils/lifecycle";export const dashboardApi = Api.injectEndpoints({endpoints: (builder) => {@@ -223,26 +221,10 @@ export const dashboardApi = Api.injectEndpoints({tag("parameter-values"),listTag("revision"),listTag("subscription"),+ // Archiving the dashboard the user has as their homepage clears the homepage server-side.+ // getCurrentUser provides this tag, so invalidating it refetches the user.+ idTag("user-homepage-dashboard", id),]),- onQueryStarted: (_, { dispatch, queryFulfilled }) =>- // Archiving the dashboard the current user has set as their custom- // homepage clears the homepage. Drop it from the cached current user- // too so the app doesn't redirect to an archived dashboard.- handleQueryFulfilled(queryFulfilled, (dashboard) => {- if (dashboard.archived) {- dispatch(- userApi.util.updateQueryData(- "getCurrentUser",- undefined,- (draft) => {- if (draft?.custom_homepage?.dashboard_id === dashboard.id) {- draft.custom_homepage = null;- }- },- ),- );- }- }),}),deleteDashboard: builder.mutation<void, DashboardId>({query: (id) => ({diff --git a/frontend/src/metabase/api/tags/constants.ts b/frontend/src/metabase/api/tags/constants.tsindex f85b6552f63..2eed1eca48b 100644--- a/frontend/src/metabase/api/tags/constants.ts+++ b/frontend/src/metabase/api/tags/constants.ts@@ -66,6 +66,7 @@ export const TAG_TYPES = ["transform-inspector-lens","user","current-user",+ "user-homepage-dashboard","public-dashboard","embed-dashboard","public-card",diff --git a/frontend/src/metabase/api/user.ts b/frontend/src/metabase/api/user.tsindex c90ad7952d8..669eccb9cfc 100644--- a/frontend/src/metabase/api/user.ts+++ b/frontend/src/metabase/api/user.ts@@ -1,3 +1,5 @@+import type { TagDescription } from "@reduxjs/toolkit/query";+import type {CreateUserRequest,ListUsersRequest,@@ -16,6 +18,20 @@ import {provideUserListTags,provideUserTags,} from "./tags";+import type { TagType } from "./tags/constants";++const provideCurrentUserTags = (user: User): TagDescription<TagType>[] => {+ const tags = [idTag("current-user", user.id)];++ // api/dashboard.ts invalidates this tag when the homepage dashboard is archived.+ if (user.custom_homepage) {+ tags.push(+ idTag("user-homepage-dashboard", user.custom_homepage.dashboard_id),+ );+ }++ return tags;+};export const userApi = Api.injectEndpoints({endpoints: (builder) => ({@@ -48,7 +64,7 @@ export const userApi = Api.injectEndpoints({method: "GET",url: "/api/user/current",}),- providesTags: (user) => (user ? [idTag("current-user", user.id)] : []),+ providesTags: (user) => (user ? provideCurrentUserTags(user) : []),// Don't garbage-collect the current user from the cache// since it's used in many places and we don't want to refetch it unnecessarily.keepUnusedDataFor: Infinity,