Db module init tidy up (#1858)
This commit is contained in:
@@ -1,24 +1,42 @@
|
||||
import { window } from "vscode";
|
||||
import { App } from "../common/app";
|
||||
import { App, AppMode } from "../common/app";
|
||||
import { extLogger } from "../common";
|
||||
import { DisposableObject } from "../pure/disposable-object";
|
||||
import { DbConfigStore } from "./config/db-config-store";
|
||||
import { DbManager } from "./db-manager";
|
||||
import { DbPanel } from "./ui/db-panel";
|
||||
import { DbSelectionDecorationProvider } from "./ui/db-selection-decoration-provider";
|
||||
import { isCanary, isNewQueryRunExperienceEnabled } from "../config";
|
||||
|
||||
export class DbModule extends DisposableObject {
|
||||
public readonly dbManager: DbManager;
|
||||
private readonly dbConfigStore: DbConfigStore;
|
||||
|
||||
constructor(app: App) {
|
||||
private constructor(app: App) {
|
||||
super();
|
||||
|
||||
this.dbConfigStore = new DbConfigStore(app);
|
||||
this.dbManager = new DbManager(app, this.dbConfigStore);
|
||||
}
|
||||
|
||||
public async initialize(): Promise<void> {
|
||||
public static async initialize(app: App): Promise<DbModule | undefined> {
|
||||
if (
|
||||
isCanary() &&
|
||||
isNewQueryRunExperienceEnabled() &&
|
||||
app.mode === AppMode.Development
|
||||
) {
|
||||
const dbModule = new DbModule(app);
|
||||
app.subscriptions.push(dbModule);
|
||||
|
||||
await dbModule.initialize();
|
||||
|
||||
return dbModule;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private async initialize(): Promise<void> {
|
||||
void extLogger.log("Initializing database module");
|
||||
|
||||
await this.dbConfigStore.initialize();
|
||||
@@ -34,9 +52,3 @@ export class DbModule extends DisposableObject {
|
||||
window.registerFileDecorationProvider(dbSelectionDecorationProvider);
|
||||
}
|
||||
}
|
||||
|
||||
export async function initializeDbModule(app: App): Promise<DbModule> {
|
||||
const dbModule = new DbModule(app);
|
||||
await dbModule.initialize();
|
||||
return dbModule;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import {
|
||||
CliConfigListener,
|
||||
DistributionConfigListener,
|
||||
isCanary,
|
||||
isNewQueryRunExperienceEnabled,
|
||||
isVariantAnalysisLiveResultsEnabled,
|
||||
joinOrderWarningThreshold,
|
||||
MAX_QUERIES,
|
||||
@@ -136,10 +135,9 @@ import { VariantAnalysisManager } from "./remote-queries/variant-analysis-manage
|
||||
import { createVariantAnalysisContentProvider } from "./remote-queries/variant-analysis-content-provider";
|
||||
import { VSCodeMockGitHubApiServer } from "./mocks/vscode-mock-gh-api-server";
|
||||
import { VariantAnalysisResultsManager } from "./remote-queries/variant-analysis-results-manager";
|
||||
import { initializeDbModule } from "./databases/db-module";
|
||||
import { ExtensionApp } from "./common/vscode/vscode-app";
|
||||
import { RepositoriesFilterSortStateWithIds } from "./pure/variant-analysis-filter-sort";
|
||||
import { AppMode } from "./common/app";
|
||||
import { DbModule } from "./databases/db-module";
|
||||
|
||||
/**
|
||||
* extension.ts
|
||||
@@ -625,15 +623,9 @@ async function activateWithInstalledDistribution(
|
||||
|
||||
void extLogger.log("Initializing variant analysis manager.");
|
||||
|
||||
// We only want to initialize the new db panel when the newQueryRunExperience is enabled
|
||||
let dbModule;
|
||||
if (isCanary() && isNewQueryRunExperienceEnabled()) {
|
||||
const app = new ExtensionApp(ctx);
|
||||
if (app.mode === AppMode.Development) {
|
||||
dbModule = await initializeDbModule(app);
|
||||
ctx.subscriptions.push(dbModule);
|
||||
}
|
||||
}
|
||||
const app = new ExtensionApp(ctx);
|
||||
|
||||
const dbModule = await DbModule.initialize(app);
|
||||
|
||||
const variantAnalysisStorageDir = join(
|
||||
ctx.globalStorageUri.fsPath,
|
||||
@@ -650,7 +642,7 @@ async function activateWithInstalledDistribution(
|
||||
cliServer,
|
||||
variantAnalysisStorageDir,
|
||||
variantAnalysisResultsManager,
|
||||
dbModule ? dbModule.dbManager : undefined, // the dbModule is only needed when the newQueryRunExperience is enabled
|
||||
dbModule?.dbManager, // the dbModule is only needed when the newQueryRunExperience is enabled
|
||||
);
|
||||
ctx.subscriptions.push(variantAnalysisManager);
|
||||
ctx.subscriptions.push(variantAnalysisResultsManager);
|
||||
|
||||
Reference in New Issue
Block a user