Skip to content

Commit

Permalink
🐛 Bulk adding tags created "duplicate" posts_tags rows from editor po…
Browse files Browse the repository at this point in the history
…sts page

#21414
The commit includes a migration which adds a unique index to posts_tags table and handles the related error when bulk adding posts.

The errors are ignored because the tags user wants to add are added/exist. This respects the editor's expectation as posts have the tags as the end result.
  • Loading branch information
Navarjun committed Dec 3, 2024
1 parent badd6d8 commit e9b5533
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const {createIrreversibleMigration} = require('../../utils');
const {addUnique} = require('../../../schema/commands');
const logging = require('@tryghost/logging');

module.exports = createIrreversibleMigration(async (knex) => {
logging.info('Adding unique constraint to tag-post relationship');

await addUnique('posts_tags', ['tag_id', 'post_id'], knex);
});
2 changes: 1 addition & 1 deletion ghost/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ghost",
"version": "5.101.6",
"version": "5.102.0",
"description": "The professional publishing platform",
"author": "Ghost Foundation",
"homepage": "https://ghost.org",
Expand Down
2 changes: 1 addition & 1 deletion ghost/posts-service/lib/PostsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class PostsService {
}));
}, []);

await options.transacting('posts_tags').insert(postTags);
await options.transacting('posts_tags').insert(postTags).onConflict().ignore();
await this.models.Post.addActions('edited', postRows.map(p => p.id), options);

return {
Expand Down

0 comments on commit e9b5533

Please sign in to comment.