Skip to content

Commit de0c27d

Browse files
committed
feat(meilisearch-connector): update getContentTypesReport
to handle multiple indexes we will have one row per index name
1 parent 21d4eb1 commit de0c27d

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

server/services/meilisearch/connector.js

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -212,49 +212,53 @@ module.exports = ({ strapi, adapter, config }) => {
212212
const contentTypes = contentTypeService.getContentTypesUid()
213213

214214
const reports = await Promise.all(
215-
contentTypes.map(async contentType => {
215+
contentTypes.flatMap(async contentType => {
216216
const collectionName = contentTypeService.getCollectionName({
217217
contentType,
218218
})
219-
const indexUid = config.getIndexNameOfContentType({ contentType })
220-
const indexInMeiliSearch = indexUids.includes(indexUid)
221-
222-
const contentTypeInIndexStore =
223-
indexedContentTypes.includes(contentType)
224-
const indexed = indexInMeiliSearch && contentTypeInIndexStore
225-
226-
// safe guard in case index does not exist anymore in Meilisearch
227-
if (!indexInMeiliSearch && contentTypeInIndexStore) {
228-
await store.removeIndexedContentType({ contentType })
229-
}
230-
231-
const { numberOfDocuments = 0, isIndexing = false } =
232-
indexUids.includes(indexUid)
233-
? await this.getStats({ indexUid })
234-
: {}
235-
236-
const contentTypesWithSameIndexUid =
237-
await config.listContentTypesWithCustomIndexName({
238-
indexName: indexUid,
239-
})
240-
const numberOfEntries = await contentTypeService.totalNumberOfEntries(
241-
{
242-
contentTypes: contentTypesWithSameIndexUid,
243-
},
219+
const indexUidsForContentType = config.getIndexNamesOfContentType({
220+
contentType,
221+
})
222+
return Promise.all(
223+
indexUidsForContentType.map(async indexUid => {
224+
const indexInMeiliSearch = indexUids.includes(indexUid)
225+
const contentTypeInIndexStore =
226+
indexedContentTypes.includes(contentType)
227+
const indexed = indexInMeiliSearch && contentTypeInIndexStore
228+
229+
// safe guard in case index does not exist anymore in Meilisearch
230+
if (!indexInMeiliSearch && contentTypeInIndexStore) {
231+
await store.removeIndexedContentType({ contentType })
232+
}
233+
234+
const { numberOfDocuments = 0, isIndexing = false } =
235+
indexUids.includes(indexUid)
236+
? await this.getStats({ indexUid })
237+
: {}
238+
239+
const contentTypesWithSameIndexUid =
240+
await config.listContentTypesWithCustomIndexName({
241+
indexName: indexUid,
242+
})
243+
const numberOfEntries =
244+
await contentTypeService.totalNumberOfEntries({
245+
contentTypes: contentTypesWithSameIndexUid,
246+
})
247+
return {
248+
collection: collectionName,
249+
contentType: contentType,
250+
indexUid,
251+
indexed,
252+
isIndexing,
253+
numberOfDocuments,
254+
numberOfEntries,
255+
listened: listenedContentTypes.includes(contentType),
256+
}
257+
}),
244258
)
245-
return {
246-
collection: collectionName,
247-
contentType: contentType,
248-
indexUid,
249-
indexed,
250-
isIndexing,
251-
numberOfDocuments,
252-
numberOfEntries,
253-
listened: listenedContentTypes.includes(contentType),
254-
}
255259
}),
256260
)
257-
return { contentTypes: reports }
261+
return { contentTypes: reports.flat() }
258262
},
259263

260264
/**

0 commit comments

Comments
 (0)