Skip to content

Commit

Permalink
Merge #123
Browse files Browse the repository at this point in the history
123: Fix plugin failing when single types existed r=bidoubiwa a=bidoubiwa

Before we decide how to handle `single types` in MeiliSearch this PR fixes the issue by removing single types from the types selection in the plugin.

Fixes #122 

open issue: #124 

Co-authored-by: Charlotte Vermandel <[email protected]>
Co-authored-by: cvermand <[email protected]>
  • Loading branch information
3 people authored Apr 22, 2021
2 parents 3302247 + 0d84570 commit 475cc3a
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 2 deletions.
16 changes: 14 additions & 2 deletions controllers/meilisearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,18 @@ async function fetchRowBatch({ start, limit, collection }) {
})
}

function getCollectionTypes() {
const services = strapi.services
return Object.keys(services).filter(type => {
return services[type].count
})
}

async function numberOfRowsInCollection({ collection }) {
return strapi.services[collection].count({ _publicationState: 'preview' })
return (
strapi.services[collection].count &&
strapi.services[collection].count({ _publicationState: 'preview' })
)
}

async function batchAddCollection(ctx) {
Expand Down Expand Up @@ -170,7 +180,9 @@ async function getStats({ collection }) {
async function getCollections() {
const indexes = await getIndexes()
const hookedCollections = await getHookedCollections()
const collections = Object.keys(strapi.services).map(async collection => {
const collectionTypes = getCollectionTypes()

const collections = collectionTypes.map(async collection => {
const existInMeilisearch = !!indexes.find(
index => index.name === collection
)
Expand Down
Binary file modified playground/.tmp/data.db
Binary file not shown.
28 changes: 28 additions & 0 deletions playground/api/single-type-test/config/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"routes": [
{
"method": "GET",
"path": "/single-type-test",
"handler": "single-type-test.find",
"config": {
"policies": []
}
},
{
"method": "PUT",
"path": "/single-type-test",
"handler": "single-type-test.update",
"config": {
"policies": []
}
},
{
"method": "DELETE",
"path": "/single-type-test",
"handler": "single-type-test.delete",
"config": {
"policies": []
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
* to customize this controller
*/

module.exports = {};
8 changes: 8 additions & 0 deletions playground/api/single-type-test/models/single-type-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks)
* to customize this model
*/

module.exports = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"kind": "singleType",
"collectionName": "single_type_tests",
"info": {
"name": "Single Type Test"
},
"options": {
"increments": true,
"timestamps": true,
"draftAndPublish": true
},
"attributes": {
"title": {
"type": "string"
}
}
}
8 changes: 8 additions & 0 deletions playground/api/single-type-test/services/single-type-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

/**
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services)
* to customize this service
*/

module.exports = {};
13 changes: 13 additions & 0 deletions playground/components/test/component-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"collectionName": "components_test_component_tests",
"info": {
"name": "Component-test",
"icon": "bong"
},
"options": {},
"attributes": {
"title": {
"type": "string"
}
}
}

0 comments on commit 475cc3a

Please sign in to comment.