Browse Source

feat: Sync model indexes on data module startup

Owen Diffey 11 months ago
parent
commit
63090ed872
1 changed files with 13 additions and 0 deletions
  1. 13 0
      backend/src/modules/DataModule.ts

+ 13 - 0
backend/src/modules/DataModule.ts

@@ -58,6 +58,8 @@ export default class DataModule extends BaseModule {
 
 		await this.loadModels();
 
+		await this.syncModelIndexes();
+
 		// @ts-ignore
 		//        this.redisClient = createClient({ ...config.get("redis") });
 		//
@@ -157,6 +159,17 @@ export default class DataModule extends BaseModule {
 		};
 	}
 
+	/**
+	 * syncModelIndexes - Sync indexes for all models
+	 */
+	private async syncModelIndexes() {
+		if (!this.models) throw new Error("Models not loaded");
+
+		await Promise.all(
+			Object.values(this.models).map(model => model.syncIndexes())
+		);
+	}
+
 	/**
 	 * getModel - Get model
 	 *