Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

2.3 KB
Raw Blame
import { PLUGIN_CACHING } from "metabase/plugins";
import { hasPremiumFeature } from "metabase-enterprise/settings";

import { DashboardAndQuestionCachingTab } from "./components/DashboardAndQuestionCachingTab";
import { DatabaseCachingEditor } from "./components/DatabaseCachingEditor";
import { InvalidateNowButton } from "./components/InvalidateNowButton";
import { MetricCachingModal } from "./components/MetricCachingModal";
import { PreemptiveCachingSwitch } from "./components/PreemptiveCachingSwitch";
import { SidebarCacheForm } from "./components/SidebarCacheForm";
import { SidebarCacheSection } from "./components/SidebarCacheSection";
import { StrategyEditorForQuestionsAndDashboards } from "./components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards";
import {
  enterpriseOnlyCachingStrategies,
  getEnterprisePerformanceTabMetadata,
} from "./constants";
import { hasQuestionCacheSection } from "./utils";

/**
 * Initialize caching plugin features that depend on hasPremiumFeature.
 */
export function initializePlugin() {
  if (hasPremiumFeature("cache_granular_controls")) {
    PLUGIN_CACHING.isGranularCachingEnabled = () => true;
    PLUGIN_CACHING.DatabaseCachingEditor = DatabaseCachingEditor;
    PLUGIN_CACHING.hasQuestionCacheSection = hasQuestionCacheSection;
    PLUGIN_CACHING.canOverrideRootStrategy = true;
    PLUGIN_CACHING.InvalidateNowButton = InvalidateNowButton;
    PLUGIN_CACHING.SidebarCacheSection = SidebarCacheSection;
    PLUGIN_CACHING.SidebarCacheForm = SidebarCacheForm;
    PLUGIN_CACHING.strategies = {
      inherit: PLUGIN_CACHING.strategies.inherit,
      duration: enterpriseOnlyCachingStrategies.duration,
      schedule: enterpriseOnlyCachingStrategies.schedule,
      ttl: PLUGIN_CACHING.strategies.ttl,
      nocache: PLUGIN_CACHING.strategies.nocache,
    };
    PLUGIN_CACHING.DashboardAndQuestionCachingTab =
      DashboardAndQuestionCachingTab;
    PLUGIN_CACHING.StrategyEditorForQuestionsAndDashboards =
      StrategyEditorForQuestionsAndDashboards;
    PLUGIN_CACHING.getTabMetadata = getEnterprisePerformanceTabMetadata;
    PLUGIN_CACHING.MetricCachingModal = MetricCachingModal;
  }

  if (hasPremiumFeature("cache_preemptive")) {
    PLUGIN_CACHING.PreemptiveCachingSwitch = PreemptiveCachingSwitch;
  }
}