Browse Source

refactor: improve performance of using station history model

Kristian Vos 1 year ago
parent
commit
c7905d507a
2 changed files with 6 additions and 5 deletions
  1. 1 2
      backend/logic/actions/stations.js
  2. 5 3
      backend/logic/stations.js

+ 1 - 2
backend/logic/actions/stations.js

@@ -1037,8 +1037,7 @@ export default {
 				},
 
 				async () => {
-					const stationHistoryModel = await DBModule.runJob("GET_MODEL", { modelName: "stationHistory" });
-					const response = await stationHistoryModel
+					const response = await StationsModule.stationHistoryModel
 						.find({ stationId }, { documentVersion: 0, __v: 0 })
 						.sort({ "payload.skippedAt": -1 })
 						.limit(250);

+ 5 - 3
backend/logic/stations.js

@@ -127,6 +127,10 @@ class _StationsModule extends CoreClass {
 		const stationModel = (this.stationModel = await DBModule.runJob("GET_MODEL", { modelName: "station" }));
 		const stationSchema = (this.stationSchema = await CacheModule.runJob("GET_SCHEMA", { schemaName: "station" }));
 
+		const stationHistoryModel = (this.stationHistoryModel = await DBModule.runJob("GET_MODEL", {
+			modelName: "stationHistory"
+		}));
+
 		return new Promise((resolve, reject) => {
 			async.waterfall(
 				[
@@ -987,9 +991,7 @@ class _StationsModule extends CoreClass {
 
 		const { stationId, currentSong, skipReason, skippedAt } = payload;
 
-		const stationHistoryModel = await DBModule.runJob("GET_MODEL", { modelName: "stationHistory" });
-
-		let document = await stationHistoryModel.create({
+		let document = await StationsModule.stationHistoryModel.create({
 			stationId,
 			type: "song_played",
 			payload: {