Преглед изворни кода

refactor(YouTube): Reset redis cache on api request reset

Owen Diffey пре 2 година
родитељ
комит
cf046001ed
1 измењених фајлова са 69 додато и 10 уклоњено
  1. 69 10
      backend/logic/youtube.js

+ 69 - 10
backend/logic/youtube.js

@@ -959,23 +959,82 @@ class _YouTubeModule extends CoreClass {
 
 	RESET_STORED_API_REQUESTS(payload) {
 		return new Promise((resolve, reject) => {
-			YouTubeModule.youtubeApiRequestModel.deleteMany({}, err => {
-				if (err) reject(new Error("Couldn't reset stored YouTube API requests."));
-				else {
-					resolve();
+			async.waterfall(
+				[
+					next => {
+						YouTubeModule.youtubeApiRequestModel.deleteMany({}, err => {
+							if (err) next("Couldn't reset stored YouTube API requests.");
+							else {
+								next();
+							}
+						});
+					},
+
+					next => {
+						CacheModule.runJob(
+							"DEL",
+							{key: "youtubeApiRequestParams"},
+							this
+						).then(next).catch(err => next(err));
+					},
+
+					next => {
+						CacheModule.runJob(
+							"DEL",
+							{key: "youtubeApiRequestResults"},
+							this
+						).then(next).catch(err => next(err));
+					}
+				],
+				err => {
+					if (err) reject(new Error(err));
+					else resolve();
 				}
-			});
+			);
 		});
 	}
 
 	REMOVE_STORED_API_REQUEST(payload) {
 		return new Promise((resolve, reject) => {
-			YouTubeModule.youtubeApiRequestModel.deleteOne({_id: payload.requestId}, err => {
-				if (err) reject(new Error("Couldn't remove stored YouTube API request."));
-				else {
-					resolve();
+			
+			async.waterfall(
+				[
+					next => {
+						YouTubeModule.youtubeApiRequestModel.deleteOne({_id: payload.requestId}, err => {
+							if (err) next("Couldn't remove stored YouTube API request.");
+							else {
+								next();
+							}
+						});
+					},
+
+					next => {
+						CacheModule.runJob(
+							"HDEL",
+							{
+								table: "youtubeApiRequestParams",
+								key: payload.requestId.toString()
+							},
+							this
+						).then(next).catch(err => next(err));
+					},
+
+					next => {
+						CacheModule.runJob(
+							"HDEL",
+							{
+								table: "youtubeApiRequestResults",
+								key: payload.requestId.toString()
+							},
+							this
+						).then(next).catch(err => next(err));
+					}
+				],
+				err => {
+					if (err) reject(new Error(err));
+					else resolve();
 				}
-			});
+			);
 		});
 	}
 }