@fourlights/strapi-plugin-deep-populate 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/index.js +15 -9
- package/dist/server/index.mjs +15 -9
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -65,7 +65,7 @@ const schema$1 = {
|
|
|
65
65
|
type: "json",
|
|
66
66
|
configurable: false
|
|
67
67
|
},
|
|
68
|
-
dependencies: { type: "
|
|
68
|
+
dependencies: { type: "text", configurable: false }
|
|
69
69
|
},
|
|
70
70
|
// experimental feature:
|
|
71
71
|
indexes: [
|
|
@@ -140,13 +140,13 @@ const register = async ({ strapi: strapi2 }) => {
|
|
|
140
140
|
const tableName = "caches";
|
|
141
141
|
const columnName = "dependencies";
|
|
142
142
|
const hasIndex = await hasDeepPopulateCacheFullTextIndex(strapi2.db, tableName, columnName);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
const hasTable = await strapi2.db.connection.schema.hasTable(tableName);
|
|
144
|
+
const hasColumn = hasTable && await strapi2.db.connection.schema.hasColumn(tableName, columnName);
|
|
145
|
+
const cacheIsEnabled = strapi2.config.get("plugin::deep-populate").cachePopulate === true;
|
|
146
|
+
const shouldCreateIndex = cacheIsEnabled && hasTable && hasColumn && !hasIndex;
|
|
147
|
+
const shouldRemoveIndex = hasIndex && (!cacheIsEnabled || !hasTable || !hasColumn);
|
|
148
|
+
if (shouldCreateIndex) await addDeepPopulateCacheFullTextIndex(strapi2.db, tableName, columnName);
|
|
149
|
+
if (shouldRemoveIndex) await removeDeepPopulateCacheFullTextIndex(strapi2.db, tableName, columnName);
|
|
150
150
|
});
|
|
151
151
|
strapi2.documents.use(async (context, next) => {
|
|
152
152
|
const { cachePopulate, augmentPopulateStar } = strapi2.config.get("plugin::deep-populate");
|
|
@@ -200,7 +200,13 @@ const cache = ({ strapi: strapi2 }) => ({
|
|
|
200
200
|
return entry ? entry.populate : null;
|
|
201
201
|
},
|
|
202
202
|
async set({ populate: populate2, dependencies, ...params }) {
|
|
203
|
-
|
|
203
|
+
const documentService = strapi2.documents("plugin::deep-populate.cache");
|
|
204
|
+
const hash = getHash(params);
|
|
205
|
+
const entry = await documentService.findFirst({ filters: { hash: { $eq: hash } } });
|
|
206
|
+
return entry ? await documentService.update({
|
|
207
|
+
documentId: entry.documentId,
|
|
208
|
+
data: { populate: populate2, dependencies: dependencies.join(",") }
|
|
209
|
+
}) : await documentService.create({ data: { hash, params, populate: populate2, dependencies: dependencies.join(",") } });
|
|
204
210
|
},
|
|
205
211
|
async clear(params) {
|
|
206
212
|
const entry = await strapi2.documents("plugin::deep-populate.cache").findFirst({ filters: { hash: { $eq: getHash(params) } } });
|
package/dist/server/index.mjs
CHANGED
|
@@ -51,7 +51,7 @@ const schema$1 = {
|
|
|
51
51
|
type: "json",
|
|
52
52
|
configurable: false
|
|
53
53
|
},
|
|
54
|
-
dependencies: { type: "
|
|
54
|
+
dependencies: { type: "text", configurable: false }
|
|
55
55
|
},
|
|
56
56
|
// experimental feature:
|
|
57
57
|
indexes: [
|
|
@@ -126,13 +126,13 @@ const register = async ({ strapi: strapi2 }) => {
|
|
|
126
126
|
const tableName = "caches";
|
|
127
127
|
const columnName = "dependencies";
|
|
128
128
|
const hasIndex = await hasDeepPopulateCacheFullTextIndex(strapi2.db, tableName, columnName);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
const hasTable = await strapi2.db.connection.schema.hasTable(tableName);
|
|
130
|
+
const hasColumn = hasTable && await strapi2.db.connection.schema.hasColumn(tableName, columnName);
|
|
131
|
+
const cacheIsEnabled = strapi2.config.get("plugin::deep-populate").cachePopulate === true;
|
|
132
|
+
const shouldCreateIndex = cacheIsEnabled && hasTable && hasColumn && !hasIndex;
|
|
133
|
+
const shouldRemoveIndex = hasIndex && (!cacheIsEnabled || !hasTable || !hasColumn);
|
|
134
|
+
if (shouldCreateIndex) await addDeepPopulateCacheFullTextIndex(strapi2.db, tableName, columnName);
|
|
135
|
+
if (shouldRemoveIndex) await removeDeepPopulateCacheFullTextIndex(strapi2.db, tableName, columnName);
|
|
136
136
|
});
|
|
137
137
|
strapi2.documents.use(async (context, next) => {
|
|
138
138
|
const { cachePopulate, augmentPopulateStar } = strapi2.config.get("plugin::deep-populate");
|
|
@@ -186,7 +186,13 @@ const cache = ({ strapi: strapi2 }) => ({
|
|
|
186
186
|
return entry ? entry.populate : null;
|
|
187
187
|
},
|
|
188
188
|
async set({ populate: populate2, dependencies, ...params }) {
|
|
189
|
-
|
|
189
|
+
const documentService = strapi2.documents("plugin::deep-populate.cache");
|
|
190
|
+
const hash = getHash(params);
|
|
191
|
+
const entry = await documentService.findFirst({ filters: { hash: { $eq: hash } } });
|
|
192
|
+
return entry ? await documentService.update({
|
|
193
|
+
documentId: entry.documentId,
|
|
194
|
+
data: { populate: populate2, dependencies: dependencies.join(",") }
|
|
195
|
+
}) : await documentService.create({ data: { hash, params, populate: populate2, dependencies: dependencies.join(",") } });
|
|
190
196
|
},
|
|
191
197
|
async clear(params) {
|
|
192
198
|
const entry = await strapi2.documents("plugin::deep-populate.cache").findFirst({ filters: { hash: { $eq: getHash(params) } } });
|
package/package.json
CHANGED