From 00f70a445b62610d878c710553a9806bf4c85bdb Mon Sep 17 00:00:00 2001 From: Sag Date: Wed, 16 Oct 2024 11:00:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20missing=20incoming=20rec?= =?UTF-8?q?ommendations=20(#21317)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- ghost/core/core/server/models/mention.js | 2 +- ghost/recommendations/src/IncomingRecommendationService.ts | 6 ++++-- .../test/IncomingRecommendationService.test.ts | 4 ++++ ghost/webmentions/lib/Mention.js | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ghost/core/core/server/models/mention.js b/ghost/core/core/server/models/mention.js index c5e849594a..269bf71f59 100644 --- a/ghost/core/core/server/models/mention.js +++ b/ghost/core/core/server/models/mention.js @@ -6,7 +6,7 @@ const Mention = ghostBookshelf.Model.extend({ deleted: false, verified: false }, - enforcedFilters() { + defaultFilters() { return 'deleted:false'; } }, { diff --git a/ghost/recommendations/src/IncomingRecommendationService.ts b/ghost/recommendations/src/IncomingRecommendationService.ts index 8d7c3b293b..60aca0c3d3 100644 --- a/ghost/recommendations/src/IncomingRecommendationService.ts +++ b/ghost/recommendations/src/IncomingRecommendationService.ts @@ -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}); } diff --git a/ghost/recommendations/test/IncomingRecommendationService.test.ts b/ghost/recommendations/test/IncomingRecommendationService.test.ts index 37c949d956..8511022ee0 100644 --- a/ghost/recommendations/test/IncomingRecommendationService.test.ts +++ b/ghost/recommendations/test/IncomingRecommendationService.test.ts @@ -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; } diff --git a/ghost/webmentions/lib/Mention.js b/ghost/webmentions/lib/Mention.js index 6fc029e133..2a2c25d2a6 100644 --- a/ghost/webmentions/lib/Mention.js +++ b/ghost/webmentions/lib/Mention.js @@ -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})); } }