perf: Move collection sorting to frontend (#3475)
* perf: Move collection sorting to frontend, on demand, memoized * fix: Add default
This commit is contained in:
29
server/migrations/20220430043135-collection-sort-backfill.js
Normal file
29
server/migrations/20220430043135-collection-sort-backfill.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface) => {
|
||||
let again = 1;
|
||||
|
||||
while (again) {
|
||||
console.log("Backfilling collection sort…");
|
||||
const [, metadata] = await queryInterface.sequelize.query(`
|
||||
WITH rows AS (
|
||||
SELECT id FROM collections WHERE "sort" IS NULL ORDER BY id LIMIT 1000
|
||||
)
|
||||
UPDATE collections
|
||||
SET "sort" = :sort::jsonb
|
||||
WHERE EXISTS (SELECT * FROM rows WHERE collections.id = rows.id)
|
||||
`, {
|
||||
replacements: {
|
||||
sort: JSON.stringify({ field: "title", direction: "asc" }),
|
||||
}
|
||||
});
|
||||
|
||||
again = metadata.rowCount;
|
||||
}
|
||||
},
|
||||
|
||||
down: async () => {
|
||||
// cannot be undone
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user