Skip to content

Commit fbacae0

Browse files
committed
fix: get indexes limited to 20 indexes
1 parent 9f56236 commit fbacae0

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

server/__mocks__/meilisearch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const updateSettingsMock = jest.fn(() => 10)
44
const deleteDocuments = jest.fn(() => {
55
return [{ taskUid: 1 }, { taskUid: 2 }]
66
})
7-
const getIndexes = jest.fn(() => {
8-
return { results: [{ uid: 'my_restaurant' }, { uid: 'restaurant' }] }
7+
const getIndexUids = jest.fn(() => {
8+
return ['my_restaurant', 'restaurant']
99
})
1010

1111
const getTasks = jest.fn(() => {
@@ -33,7 +33,7 @@ const mockIndex = jest.fn(() => ({
3333
// @ts-ignore
3434
const mock = jest.fn().mockImplementation(() => {
3535
return {
36-
getIndexes,
36+
getIndexUids,
3737
index: mockIndex,
3838
getTasks,
3939
}

server/__tests__/meilisearch.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ describe('Tests content types', () => {
2323
strapi: customStrapi,
2424
})
2525

26-
const indexes = await meilisearchService.getIndexes()
26+
const indexes = await meilisearchService.getIndexUids()
2727

28-
expect(indexes).toEqual([{ uid: 'my_restaurant' }, { uid: 'restaurant' }])
28+
expect(indexes).toEqual(['my_restaurant', 'restaurant'])
2929
})
3030

3131
test('Test to delete entries from Meilisearch', async () => {

server/bootstrap.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ async function syncIndexedCollections({
3131
contentTypeService,
3232
meilisearch,
3333
}) {
34-
const indexes = await meilisearch.getIndexes()
35-
const indexUids = indexes.map(index => index.uid)
34+
const indexUids = await meilisearch.getIndexUids()
3635
// All indexed contentTypes
3736
const indexedContentTypes = await store.getIndexedContentTypes()
3837
const contentTypes = contentTypeService.getContentTypesUid()

server/services/meilisearch/connector.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ module.exports = ({ strapi, adapter, config }) => {
6565

6666
return {
6767
/**
68-
* Get indexes with a safe guard in case of error.
68+
* Get index uids with a safe guard in case of error.
6969
*
7070
* @returns { Promise<import("meilisearch").Index[]> }
7171
*/
72-
getIndexes: async function () {
72+
getIndexUids: async function () {
7373
try {
7474
const { apiKey, host } = await store.getCredentials()
7575
const client = Meilisearch({ apiKey, host })
76-
const { results: indexes } = await client.getIndexes()
77-
return indexes
76+
const { indexes } = await client.getStats()
77+
return Object.keys(indexes)
7878
} catch (e) {
7979
strapi.log.error(`meilisearch: ${e.message}`)
8080
return []
@@ -176,8 +176,7 @@ module.exports = ({ strapi, adapter, config }) => {
176176
* }>}>} - List of contentTypes reports.
177177
*/
178178
getContentTypesReport: async function () {
179-
const indexes = await this.getIndexes()
180-
const indexUids = indexes.map(index => index.uid)
179+
const indexUids = await this.getIndexUids()
181180

182181
// All listened contentTypes
183182
const listenedContentTypes = await store.getListenedContentTypes()

0 commit comments

Comments
 (0)