From f8b5151411bd6213870c8ffb8182f24f9dd233fc Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Fri, 7 Aug 2020 13:38:07 -0700 Subject: [PATCH 1/3] Bump index-recipe job dates --- kube/configs/index-recipes.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kube/configs/index-recipes.yml b/kube/configs/index-recipes.yml index 239592a68..6343c97e9 100644 --- a/kube/configs/index-recipes.yml +++ b/kube/configs/index-recipes.yml @@ -1,12 +1,12 @@ apiVersion: batch/v1 kind: Job metadata: - name: rs-index-recipes-2020-03-10 + name: rs-index-recipes-2020-08-07 spec: template: spec: containers: - - name: rs-index-recipes-2020-03-10 + - name: rs-index-recipes-2020-08-07 image: julianpoy/recipesage:api-2.4.0-b6 command: ["node"] args: ["src/index.app.js"] @@ -21,7 +21,7 @@ spec: name: rs-api-env env: - name: INDEX_BEFORE - value: "2020-03-10 22:30" + value: "2020-08-07 00:00" restartPolicy: Never imagePullSecrets: - name: myregistrykey From 0c66ace08b93c4905f741d3fa241eb3a6b2c9c14 Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Fri, 7 Aug 2020 13:38:38 -0700 Subject: [PATCH 2/3] Add deleteRecipesByUser method to elastic service --- Backend/src/services/elastic.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Backend/src/services/elastic.js b/Backend/src/services/elastic.js index af4e025eb..b13962278 100644 --- a/Backend/src/services/elastic.js +++ b/Backend/src/services/elastic.js @@ -103,6 +103,27 @@ const deleteRecipes = recipeIds => { }); }; +const deleteRecipesByUser = userId => { + if (!ENABLE) return Promise.resolve(); + + return client.deleteByQuery({ + index: getFullIndexName('recipes'), + body: { + query: { + bool: { + filter: { + query_string: { + fields: ["userId"], + analyzer: "standard", + query: userId, + }, + }, + }, + }, + }, + }); +}; + const searchRecipes = (userId, queryString) => { if (!ENABLE) throw new Error("ElasticSearch not enabled"); @@ -142,5 +163,6 @@ const searchRecipes = (userId, queryString) => { module.exports = { indexRecipes, deleteRecipes, + deleteRecipesByUser, searchRecipes }; From 57415d448976758f23dab6a123cb3b5c0ecec495 Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Fri, 7 Aug 2020 13:38:54 -0700 Subject: [PATCH 3/3] Add reindex route, elastic delete on user deleteall --- Backend/src/routes/recipes.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Backend/src/routes/recipes.js b/Backend/src/routes/recipes.js index 6d7968043..bafe0362f 100644 --- a/Backend/src/routes/recipes.js +++ b/Backend/src/routes/recipes.js @@ -653,11 +653,13 @@ router.delete( }, transaction: t }) - }) + }).then(() => { + return ElasticService.deleteRecipesByUser(res.locals.session.userId); + }); }).then(() => { res.status(200).send({}) }).catch(next); -}) +}); router.post( '/delete-bulk', @@ -775,5 +777,18 @@ router.delete( .catch(next); }); +router.post('/reindex', MiddlewareService.validateSession(['user']), async (req, res, next) => { + const recipes = await Recipe.findAll({ + where: { + userId: res.locals.session.userId, + } + }); + + await ElasticService.deleteRecipesByUser(res.locals.session.userId); + + await ElasticService.indexRecipes(recipes); + + res.status(200).send({}); +}); module.exports = router;