From 0329b41357fb1913f9b0c6fe7118e1da8bd55c9a Mon Sep 17 00:00:00 2001 From: Akhilesh Thite Date: Wed, 5 Jun 2024 19:50:19 +0530 Subject: [PATCH] perf: optimize note ingestion by checking actor alignment in ingestActivity --- .vscode/settings.json | 3 +++ db.js | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f3a291 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/db.js b/db.js index 4760e8a..1d1113b 100644 --- a/db.js +++ b/db.js @@ -356,11 +356,16 @@ export class ActivityPubDB extends EventTarget { console.log('Ingesting activity:', activity) await this.db.put(ACTIVITIES_STORE, activity) - if (activity.type === TYPE_CREATE || activity.type === TYPE_UPDATE) { + if ((activity.type === TYPE_CREATE || activity.type === TYPE_UPDATE) && activity.actor) { const note = await this.#get(activity.object) if (note.type === TYPE_NOTE) { - console.log('Ingesting note:', note) - await this.ingestNote(note, true) + // Only ingest the note if the note's attributed actor is the same as the activity's actor + if (note.attributedTo === activity.actor) { + console.log('Ingesting note:', note) + await this.ingestNote(note) + } else { + console.log(`Skipping note ingestion for actor mismatch: Note attributed to ${note.attributedTo}, but activity actor is ${activity.actor}`) + } } } else if (activity.type === TYPE_DELETE) { // Handle 'Delete' activity type @@ -370,10 +375,10 @@ export class ActivityPubDB extends EventTarget { return true } - async ingestNote (note, forceIngest = false) { + async ingestNote (note) { const isFollowed = await this.isActorFollowed(note.attributedTo) - if (!isFollowed && !forceIngest) { - console.log('Skipping note ingestion as actor is not followed and forceIngest is false.') + if (!isFollowed) { + console.log('Skipping note ingestion as actor is not followed.') return }