Skip to content

Commit

Permalink
🐛 Fixed missing incoming recommendations (TryGhost#21317)
Browse files Browse the repository at this point in the history
ref https://linear.app/tryghost/issue/ONC-433

- due to a regression introduced in commit 871d21a, incoming
recommendations were not rendering in Admin Settings anymore, as they
were marked as deleted
- this commit updates the refresh logic of incoming recommendations on
boot: previously deleted incoming recommendations are refetched, and if
now available, restored
- when a recommendation is restored, we don't send a staff email
notification
  • Loading branch information
sagzy authored and tilak999 committed Nov 20, 2024
1 parent c2045d7 commit 645e5d4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ghost/core/core/server/models/mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Mention = ghostBookshelf.Model.extend({
deleted: false,
verified: false
},
enforcedFilters() {
defaultFilters() {
return 'deleted:false';
}
}, {
Expand Down
6 changes: 4 additions & 2 deletions ghost/recommendations/src/IncomingRecommendationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ export class IncomingRecommendationService {
}

async #updateIncomingRecommendations() {
// Note: we also recheck recommendations that were not verified (verification could have failed)
const filter = this.#getMentionFilter();
// We refresh all incoming recommendations, including:
// - recommendations that were not verified, as the verification could have failed
// - recommendations that were deleted previously. Implementation note: given that we have `deleted:false` as default filter in the Mention model, we need to override it here
const filter = this.#getMentionFilter() + '+deleted:[true,false]';
await this.#mentionsApi.refreshMentions({filter, limit: 100});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ describe('IncomingRecommendationService', function () {
await service.init();
clock.tick(1000 * 60 * 60 * 24);
assert(refreshMentions.calledOnce);
assert(refreshMentions.calledWith({
filter: `source:~$'/.well-known/recommendations.json'+deleted:[true,false]`,
limit: 100
}));
} finally {
process.env.NODE_ENV = saved;
}
Expand Down
1 change: 0 additions & 1 deletion ghost/webmentions/lib/Mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = class Mention {
// When an earlier mention is deleted, but then it gets verified again, we need to undelete it
if (this.#deleted) {
this.#deleted = false;
this.events.push(MentionCreatedEvent.create({mention: this}));
}
}

Expand Down

0 comments on commit 645e5d4

Please sign in to comment.