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
Remove persisted models entity (#73682)
Romeo Van Snick81de8a690f0b
diff --git a/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobModal.tsx b/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobModal.tsxindex c8e9d8a9a19..914766223e1 100644--- a/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobModal.tsx+++ b/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobModal.tsx@@ -1,47 +1,30 @@import { useEffect, useMemo } from "react";import { usePrevious } from "react-use";import { t } from "ttag";-import _ from "underscore";+import {+ skipToken,+ useGetPersistedInfoQuery,+ useRefreshModelCacheMutation,+} from "metabase/api";import { Button } from "metabase/common/components/Button";import { Link } from "metabase/common/components/Link";import { ModalContent } from "metabase/common/components/ModalContent";import ButtonsS from "metabase/css/components/buttons.module.css";-import { PersistedModels } from "metabase/entities/persisted-models";-import { connect } from "metabase/redux";-import type { ModelCacheRefreshStatus } from "metabase-types/api";+import type { ModalComponentProps } from "metabase/hoc/ModalRoute";+import { parseNumberParam } from "metabase/urls";import { ErrorBox } from "./ModelCacheRefreshJobs.styled";-type ModelCacheRefreshJobModalOwnProps = {- params: {- jobId: string;- };- onClose: () => void;-};--type ModelCacheRefreshJobModalStateProps = {- onRefresh: (job: ModelCacheRefreshStatus) => void;-};--type PersistedModelsLoaderProps = {- persistedModel: ModelCacheRefreshStatus;-};--type ModelCacheRefreshJobModalProps = ModelCacheRefreshJobModalOwnProps &- ModelCacheRefreshJobModalStateProps &- PersistedModelsLoaderProps;--const mapDispatchToProps = {- onRefresh: (job: ModelCacheRefreshStatus) =>- PersistedModels.objectActions.refreshCache(job),-};--function ModelCacheRefreshJobModalInner({- persistedModel,+export function ModelCacheRefreshJobModal({+ params,onClose,- onRefresh,-}: ModelCacheRefreshJobModalProps) {+}: ModalComponentProps) {+ const jobId = parseNumberParam(params.jobId);+ const { data: persistedModel } = useGetPersistedInfoQuery(+ jobId !== undefined ? jobId : skipToken,+ );+ const [refreshModelCache] = useRefreshModelCacheMutation();const prevModelInfo = usePrevious(persistedModel);useEffect(() => {@@ -60,7 +43,7 @@ function ModelCacheRefreshJobModalInner({return null;}- const onRefreshClick = () => onRefresh(persistedModel);+ const onRefreshClick = () => refreshModelCache(persistedModel.card_id);return [<Button@@ -74,7 +57,7 @@ function ModelCacheRefreshJobModalInner({to={`/model/${persistedModel.card_id}/query`}>{t`Edit model`}</Link>,];- }, [persistedModel, onRefresh]);+ }, [persistedModel, refreshModelCache]);return (<ModalContent title={t`Oh oh…`} onClose={onClose} footer={footer}>@@ -82,12 +65,3 @@ function ModelCacheRefreshJobModalInner({</ModalContent>);}--export const ModelCacheRefreshJobModal = _.compose(- connect(null, mapDispatchToProps),- PersistedModels.load({- id: (state: unknown, props: ModelCacheRefreshJobModalOwnProps) =>- props.params.jobId,- loadingAndErrorWrapper: false,- }),-)(ModelCacheRefreshJobModalInner);diff --git a/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobs.tsx b/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobs.tsxindex bced9f6ec4d..dfb505a05c4 100644--- a/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobs.tsx+++ b/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobs.tsx@@ -8,7 +8,10 @@ import {SettingsPageWrapper,SettingsSection,} from "metabase/admin/components/SettingsSection";-import { useListPersistedInfoQuery } from "metabase/api";+import {+ useListPersistedInfoQuery,+ useRefreshModelCacheMutation,+} from "metabase/api";import { DateTime } from "metabase/common/components/DateTime";import { EmptyState } from "metabase/common/components/EmptyState";import { Link } from "metabase/common/components/Link";@@ -17,8 +20,6 @@ import { PaginationControls } from "metabase/common/components/PaginationControlimport { usePagination } from "metabase/common/hooks/use-pagination";import AdminS from "metabase/css/admin.module.css";import CS from "metabase/css/core/index.css";-import { PersistedModels } from "metabase/entities/persisted-models";-import { connect } from "metabase/redux";import { Icon, Tooltip } from "metabase/ui";import * as Urls from "metabase/urls";import { capitalize } from "metabase/utils/formatting";@@ -103,16 +104,8 @@ function JobTableItem({ job, onRefresh }: JobTableItemProps) {const PAGE_SIZE = 20;-type Props = {- onRefresh: (job: ModelCacheRefreshStatus) => void;-};--const mapDispatchToProps = {- onRefresh: (job: ModelCacheRefreshStatus) =>- PersistedModels.objectActions.refreshCache(job),-};--function ModelCacheRefreshJobsInner({ onRefresh }: Props) {+export function ModelCacheRefreshJobs() {+ const [refreshModelCache] = useRefreshModelCacheMutation();const { page, handleNextPage, handlePreviousPage } = usePagination();const { data, error, isFetching } = useListPersistedInfoQuery({limit: PAGE_SIZE,@@ -163,7 +156,7 @@ function ModelCacheRefreshJobsInner({ onRefresh }: Props) {<JobTableItemkey={job.id}job={job}- onRefresh={() => onRefresh(job)}+ onRefresh={() => refreshModelCache(job.card_id)}/>))}</tbody>@@ -185,11 +178,6 @@ function ModelCacheRefreshJobsInner({ onRefresh }: Props) {);}-export const ModelCacheRefreshJobs = connect(- null,- mapDispatchToProps,-)(ModelCacheRefreshJobsInner);-export function ModelCachePage({ children }: { children?: React.ReactNode }) {return (<SettingsPageWrapper title={t`Model cache log`}>diff --git a/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobs.unit.spec.tsx b/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobs.unit.spec.tsxindex 60568435827..f288cd5560e 100644--- a/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobs.unit.spec.tsx+++ b/frontend/src/metabase/admin/tools/components/ModelCacheRefreshJobs/ModelCacheRefreshJobs.unit.spec.tsx@@ -1,32 +1,19 @@import { setupModelPersistenceEndpoints } from "__support__/server-mocks/persist";import { renderWithProviders, screen } from "__support__/ui";-import { PersistedModels } from "metabase/entities/persisted-models";import type { ModelCacheRefreshStatus } from "metabase-types/api";import { getMockModelCacheInfo } from "metabase-types/api/mocks/models";import { ModelCacheRefreshJobs } from "./ModelCacheRefreshJobs";async function setup({ logs = [] }: { logs?: ModelCacheRefreshStatus[] } = {}) {- const onRefreshMock = jest- .spyOn(PersistedModels.objectActions, "refreshCache")- .mockReturnValue({ type: "__MOCK__" });-setupModelPersistenceEndpoints(logs);renderWithProviders(<ModelCacheRefreshJobs />);await screen.findByTestId("model-cache-logs");-- return {- onRefreshMock,- };}describe("ModelCacheRefreshJobs", () => {- afterEach(() => {- jest.resetAllMocks();- });-it("shows empty state when there are no cache logs", async () => {await setup({ logs: [] });expect(screen.getByText("No results")).toBeInTheDocument();diff --git a/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts b/frontend/src/metabase/entities/containers/rtk-query/types/entities.tsindex 13deec844cf..98286b6e471 100644--- a/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts+++ b/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts@@ -44,7 +44,6 @@ export type EntityType =| "documents"| "fields"| "groups"- | "persistedModels"| "pulses"| "questions"| "revisions"diff --git a/frontend/src/metabase/entities/index.ts b/frontend/src/metabase/entities/index.tsindex 097a0f06fa4..a5bd908d9cb 100644--- a/frontend/src/metabase/entities/index.ts+++ b/frontend/src/metabase/entities/index.ts@@ -86,7 +86,6 @@ export { Metrics as metrics } from "./metrics";export { Groups as groups } from "./groups";export { Search as search } from "./search";-export { PersistedModels as persistedModels } from "./persisted-models";export { Snippets as snippets } from "./snippets";export { entityCompatibleQuery, combineEntities } from "./utils";diff --git a/frontend/src/metabase/entities/persisted-models.js b/frontend/src/metabase/entities/persisted-models.jsdeleted file mode 100644index d7e83d1b9ef..00000000000--- a/frontend/src/metabase/entities/persisted-models.js+++ /dev/null@@ -1,114 +0,0 @@-import { createSelector } from "@reduxjs/toolkit";--import {- cardApi,- persistApi,- skipToken,- useGetPersistedInfoByCardQuery,- useGetPersistedInfoQuery,- useListPersistedInfoQuery,-} from "metabase/api";-import { PersistedModelSchema } from "metabase/schema";--import { createEntity, entityCompatibleQuery } from "./utils";--const REFRESH_CACHE = "metabase/entities/persistedModels/REFRESH_CACHE";--const getPersistedModelInfoByModelId = createSelector(- [(state) => state.entities.persistedModels, (state, props) => props.entityId],- (persistedModels, modelId) =>- Object.values(persistedModels).find((info) => info.card_id === modelId),-);--/**- * @deprecated use "metabase/api" instead- */-export const PersistedModels = createEntity({- name: "persistedModels",- nameOne: "persistedModel",- path: "/api/persist",- schema: PersistedModelSchema,-- rtk: () => ({- getUseGetQuery: () => ({- useGetQuery,- }),- useListQuery: useListPersistedInfoQuery,- }),-- api: {- get: ({ id, type }, options, dispatch) => {- return type === "byModelId"- ? entityCompatibleQuery(- id,- dispatch,- persistApi.endpoints.getPersistedInfoByCard,- )- : entityCompatibleQuery(- id,- dispatch,- persistApi.endpoints.getPersistedInfo,- );- },- list: (entityQuery, dispatch) =>- entityCompatibleQuery(- entityQuery,- dispatch,- persistApi.endpoints.listPersistedInfo,- ),- create: () => {- throw new TypeError("PersistedModels.api.create is not supported");- },- update: () => {- throw new TypeError("PersistedModels.api.update is not supported");- },- delete: () => {- throw new TypeError("PersistedModels.api.delete is not supported");- },- },-- objectActions: {- refreshCache: (job) => async (dispatch) => {- await entityCompatibleQuery(- job.card_id,- dispatch,- cardApi.endpoints.refreshModelCache,- );-- dispatch({ type: REFRESH_CACHE, payload: job });- },- },-- selectors: {- getByModelId: getPersistedModelInfoByModelId,- },-- reducer: (state = {}, { type, payload, error }) => {- if (type === REFRESH_CACHE && !error) {- return {- ...state,- [payload.id]: {- ...state[payload.id],- state: "refreshing",- refresh_begin: new Date().toUTCString(),- refresh_end: null,- },- };- }- return state;- },-});--const useGetQuery = ({ id, type }, options) => {- const persistedInfoByCard = useGetPersistedInfoByCardQuery(- type === "byModelId" ? id : skipToken,- options,- );-- const persistedInfo = useGetPersistedInfoQuery(- type === "byModelId" ? skipToken : id,- options,- );-- return type === "byModelId" ? persistedInfoByCard : persistedInfo;-};diff --git a/frontend/src/metabase/schema.js b/frontend/src/metabase/schema.jsindex 4a1b2b9441a..b852b52eaef 100644--- a/frontend/src/metabase/schema.js+++ b/frontend/src/metabase/schema.js@@ -69,7 +69,6 @@ export const ForeignKeySchema = new schema.Entity("foreignKeys");export const SegmentSchema = new schema.Entity("segments");export const MeasureSchema = new schema.Entity("measures");export const MetricSchema = new schema.Entity("metrics");-export const PersistedModelSchema = new schema.Entity("persistedModels");export const SnippetSchema = new schema.Entity("snippets");export const SnippetCollectionSchema = new schema.Entity("snippetCollections");