Skip to content

Commit

Permalink
Merge #470 #471
Browse files Browse the repository at this point in the history
470: Make afterDeleteMany a working hook r=bidoubiwa a=bidoubiwa

fixes: #467 

471: Make afterUpdateMany a working hook r=bidoubiwa a=bidoubiwa

fixes: #396

TODO
- [ ] needs to paginate on the entries

Co-authored-by: Charlotte Vermandel <[email protected]>
  • Loading branch information
meili-bors[bot] and bidoubiwa authored Jul 26, 2022
3 parents cba7071 + d058890 + bc4ef79 commit 98cab0f
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions server/services/lifecycle/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,39 @@ module.exports = ({ strapi }) => {
)
})
},
async afterUpdateMany() {
strapi.log.error(
`Meilisearch could not find an example on how to access the \`afterUpdateMany\` hook. Please consider making an issue to explain your use case`
)
async afterUpdateMany(event) {
const meilisearch = strapi
.plugin('meilisearch')
.service('meilisearch')

const nbrEntries = await contentTypeService.numberOfEntries({
contentType: contentTypeUid,
where: event.params.where,
})

const entries = []
const BATCH_SIZE = 500

for (let pos = 0; pos < nbrEntries; pos += BATCH_SIZE) {
const batch = await contentTypeService.getEntries({
contentType: contentTypeUid,
filters: event.params.where,
start: pos,
limit: BATCH_SIZE,
})
entries.push(...batch)
}

meilisearch
.updateEntriesInMeilisearch({
contentType: contentTypeUid,
entries: entries,
})
.catch(e => {
strapi.log.error(
`Meilisearch could not update the entries: ${e.message}`
)
})
},
async afterDelete(event) {
const { result, params } = event
Expand Down Expand Up @@ -106,10 +135,8 @@ module.exports = ({ strapi }) => {
)
})
},
async afterDeleteMany() {
strapi.log.error(
`Meilisearch could not find an example on how to access the \`afterDeleteMany\` hook. Please consider making an issue to explain your use case`
)
async afterDeleteMany(event) {
this.afterDelete(event)
},
})

Expand Down

0 comments on commit 98cab0f

Please sign in to comment.