Skip to content

Logical separation of app view#572

Merged
devinivy merged 12 commits intomainfrom
app-view-init
Feb 24, 2023
Merged

Logical separation of app view#572
devinivy merged 12 commits intomainfrom
app-view-init

Conversation

@devinivy
Copy link
Collaborator

@devinivy devinivy commented Feb 21, 2023

The goal here is to isolate app view functionality for the bsky application logically from the rest of the PDS, which is more focused on hosting. The app-view functionality lives inside packages/pds/src/app-view/, where lots of files have been moved or adapted out of packages/pds/src/.

Database layer

In the db layer the following tables have been separated into the app view, all related to indexing bsky records: duplicate_record, assertion, profile, post, post_hierarchy, post_entity, post_embed_image, post_embed_external, vote, repost, follow.

A few exceptions to the factoring: vote is shared by the feed.setVote method in the PDS for now. The repo_root and record tables are shared so that the app view can tell if a repo/record is moderated. And did_handle is used by both. There is also a little tangle with mutes, which logically lives under the PDS but is used in the app-view.

Service layer

The actor service has been split into the PDS's account service and the app-view's actor service. The PDS inherits the com.atproto terminology ("account"), where app-view has the app.bsky terminology ("actor"). All actor view logic is isolated within the the app-view, though it is currently used in two places in the PDS: graph.getMutes and notification.list methods.

The record service has been split into the PDS's record service and the app-view's indexing service. In short, all bsky-specific indexing logic from the record service (i.e. the plugin/processing system) has been split out into the app-view's indexing service.

In order to maintain a loose coupling between these two services, a MessageDispatcher implementing MessageQueue that handles messages immediately (i.e. in the same transaction as the send()) has been introduced. For example, when the user writes a record to their repo the PDS dispatches an "index_record" message. The app-view receives this message, performs any bsky-specific indexing, then may push some "create_notification" messages onto the message queue, which are picked-up by the PDS.

The services for the app-view live under services.appView. I see the service layer as sort of the midpoint of the architecture (between method handlers and the db model), so it's a nice place to have any coupling between app-view and PDS explicitly documented.

Still a few things to untangle, but now there's some proper logical separation between the PDS and app-view, and the overlap between the two is documented here as well as with @NOTE or @TODOs in the code.

.where('post_embed_external.postUri', 'in', postByUser)
.execute(),
this.db.db
.deleteFrom('duplicate_record')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we focus on backlinks more, we may want to make duplicate_record a bit smarter

Copy link
Collaborator

@dholms dholms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the wait for review

this is all coming together quite nicely!

@devinivy devinivy merged commit 8826ada into main Feb 24, 2023
@devinivy devinivy deleted the app-view-init branch February 24, 2023 22:22
mloar pushed a commit to mloar/atproto that referenced this pull request Nov 15, 2023
* Separate app.bsky methods out into app view

* Fix websocket issue while splitting-out app view

* Start organizing app-view tables out of pds

* Move feed service, getTimeline, vote table into app-view

* Move record processing/indexing logically out of pds and into app-view

* Pull actor service functionality into app-view

* Factor app-view user functionality out of pds, replace actor w/ account service

* Tidy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants