Skip to content

Commit

Permalink
perf: optimize note ingestion by checking actor alignment in ingestAc…
Browse files Browse the repository at this point in the history
…tivity
  • Loading branch information
akhileshthite committed Jun 5, 2024
1 parent f8e593a commit 0329b41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
17 changes: 11 additions & 6 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 0329b41

Please sign in to comment.