Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make afterUpdateMany a working hook #471

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 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) {
bidoubiwa marked this conversation as resolved.
Show resolved Hide resolved
const meilisearch = strapi
.plugin('meilisearch')
.service('meilisearch')

const nbrEntries = await contentTypeService.numberOfEntries({
contentType: contentTypeUid,
bidoubiwa marked this conversation as resolved.
Show resolved Hide resolved
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