mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Added composite index to posts table for type,status (#20437)
ref https://linear.app/tryghost/issue/CFR-35 - performance improvement intended for the content api/get helpers The posts table is shared by posts and pages and seldom is queried for both. It makes sense to add an index on type, and from the perspective of the content API, also on status as you're almost only ever querying for published posts or published pages.
This commit is contained in:
parent
897481b3b4
commit
4f6842b99a
5 changed files with 11 additions and 4 deletions
|
@ -47,8 +47,8 @@ function removeSourceFormats(frame) {
|
||||||
*/
|
*/
|
||||||
function selectAllAllowedColumns(frame) {
|
function selectAllAllowedColumns(frame) {
|
||||||
if (!frame.options.columns && !frame.options.selectRaw) {
|
if (!frame.options.columns && !frame.options.selectRaw) {
|
||||||
// Because we're returning columns directly from the table we need to remove info columns like @@UNIQUE_CONSTRAINTS@@
|
// Because we're returning columns directly from the schema we need to remove info columns like @@UNIQUE_CONSTRAINTS@@ and @@INDEXES@@
|
||||||
frame.options.selectRaw = _.keys(_.omit(postsSchema, ['lexical','mobiledoc','@@UNIQUE_CONSTRAINTS@@'])).join(',');
|
frame.options.selectRaw = _.keys(_.omit(postsSchema, ['lexical','mobiledoc','@@INDEXES@@','@@UNIQUE_CONSTRAINTS@@'])).join(',');
|
||||||
} else if (frame.options.columns) {
|
} else if (frame.options.columns) {
|
||||||
frame.options.columns = frame.options.columns.filter((column) => {
|
frame.options.columns = frame.options.columns.filter((column) => {
|
||||||
return !['mobiledoc', 'lexical'].includes(column);
|
return !['mobiledoc', 'lexical'].includes(column);
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
// For information on writing migrations, see https://www.notion.so/ghost/Database-migrations-eb5b78c435d741d2b34a582d57c24253
|
||||||
|
const {createAddIndexMigration} = require('../../utils');
|
||||||
|
|
||||||
|
module.exports = createAddIndexMigration('posts',['type','status']);
|
|
@ -93,6 +93,9 @@ module.exports = {
|
||||||
canonical_url: {type: 'text', maxlength: 2000, nullable: true},
|
canonical_url: {type: 'text', maxlength: 2000, nullable: true},
|
||||||
newsletter_id: {type: 'string', maxlength: 24, nullable: true, references: 'newsletters.id'},
|
newsletter_id: {type: 'string', maxlength: 24, nullable: true, references: 'newsletters.id'},
|
||||||
show_title_and_feature_image: {type: 'boolean', nullable: false, defaultTo: true},
|
show_title_and_feature_image: {type: 'boolean', nullable: false, defaultTo: true},
|
||||||
|
'@@INDEXES@@': [
|
||||||
|
['type','status']
|
||||||
|
],
|
||||||
'@@UNIQUE_CONSTRAINTS@@': [
|
'@@UNIQUE_CONSTRAINTS@@': [
|
||||||
['slug', 'type']
|
['slug', 'type']
|
||||||
]
|
]
|
||||||
|
|
|
@ -115,7 +115,7 @@ describe('Unit: endpoints/utils/serializers/input/posts', function () {
|
||||||
serializers.input.posts.browse(apiConfig, frame);
|
serializers.input.posts.browse(apiConfig, frame);
|
||||||
const columns = Object.keys(postsSchema);
|
const columns = Object.keys(postsSchema);
|
||||||
const parsedSelectRaw = frame.options.selectRaw.split(',').map(column => column.trim());
|
const parsedSelectRaw = frame.options.selectRaw.split(',').map(column => column.trim());
|
||||||
parsedSelectRaw.should.eql(columns.filter(column => !['mobiledoc', 'lexical','@@UNIQUE_CONSTRAINTS@@'].includes(column)));
|
parsedSelectRaw.should.eql(columns.filter(column => !['mobiledoc', 'lexical','@@UNIQUE_CONSTRAINTS@@','@@INDEXES@@'].includes(column)));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('strips mobiledoc and lexical columns from a specified columns option', function () {
|
it('strips mobiledoc and lexical columns from a specified columns option', function () {
|
||||||
|
|
|
@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
|
||||||
*/
|
*/
|
||||||
describe('DB version integrity', function () {
|
describe('DB version integrity', function () {
|
||||||
// Only these variables should need updating
|
// Only these variables should need updating
|
||||||
const currentSchemaHash = 'a04351620a75f14dfbd9158381df7f87';
|
const currentSchemaHash = '45c8072332176e0fe5a4fdff58fb2113';
|
||||||
const currentFixturesHash = 'a489d615989eab1023d4b8af0ecee7fd';
|
const currentFixturesHash = 'a489d615989eab1023d4b8af0ecee7fd';
|
||||||
const currentSettingsHash = '5c957ceb48c4878767d7d3db484c592d';
|
const currentSettingsHash = '5c957ceb48c4878767d7d3db484c592d';
|
||||||
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
||||||
|
|
Loading…
Add table
Reference in a new issue