Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved performance fetching posts #20460

Merged
merged 7 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const logging = require('@tryghost/logging');
const {createNonTransactionalMigration} = require('../../utils');
const {addIndex, dropIndex} = require('../../../schema/commands');

module.exports = createNonTransactionalMigration(
async function up(knex) {
await addIndex('posts_tags', ['post_id', 'tag_id'], knex);
},
async function down(knex) {
try {
await dropIndex('posts_tags', ['post_id', 'tag_id'], knex);
} catch (err) {
if (err.code === 'ER_DROP_INDEX_FK') {
logging.error({
message: 'Error dropping index over posts_tags(post_id, tag_id), re-adding index for post_id'
});

await addIndex('posts_tags', ['post_id'], knex);
await dropIndex('posts_tags', ['post_id', 'tag_id'], knex);
return;
}

throw err;
}
}
);
Original file line number Diff line number Diff line change
@@ -1,4 +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']);
module.exports = createAddIndexMigration('posts',['type','status','updated_at']);
7 changes: 5 additions & 2 deletions ghost/core/core/server/data/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = {
newsletter_id: {type: 'string', maxlength: 24, nullable: true, references: 'newsletters.id'},
show_title_and_feature_image: {type: 'boolean', nullable: false, defaultTo: true},
'@@INDEXES@@': [
['type','status']
['type','status','updated_at']
],
'@@UNIQUE_CONSTRAINTS@@': [
['slug', 'type']
Expand Down Expand Up @@ -298,7 +298,10 @@ module.exports = {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id'},
tag_id: {type: 'string', maxlength: 24, nullable: false, references: 'tags.id'},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0},
'@@INDEXES@@': [
['post_id','tag_id']
]
},
invites: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
Expand Down
2 changes: 1 addition & 1 deletion ghost/core/test/unit/server/data/schema/integrity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '45c8072332176e0fe5a4fdff58fb2113';
const currentSchemaHash = 'ce97eff9bf1b3c215fed1271f9275f83';
const currentFixturesHash = 'a489d615989eab1023d4b8af0ecee7fd';
const currentSettingsHash = '5c957ceb48c4878767d7d3db484c592d';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
Expand Down
Loading