Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • pleroma pleroma
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 647
    • Issues 647
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 86
    • Merge requests 86
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PleromaPleroma
  • pleromapleroma
  • Merge requests
  • !2332

FollowingRelationship storage & performance optimizations

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Ivan Tashkinov requested to merge following-relationships-optimizations into develop Mar 28, 2020
  • Overview 13
  • Commits 3
  • Pipelines 3
  • Changes 17

FollowingRelationship storage & performance optimizations:

  1. state is now ecto_enum-driven integer field mapped to FollowingRelationshipStateEnum. Storing enum-like fields as strings isn't a good approach, strings take much more space, prone to typos (unlike ecto_enum enum atoms — wrong atom couldn't be mapped to underlying integer value thus raising an error) etc.

  2. Added an index on following_relationships.following_id since that would help existing queries (e.g. see Pleroma.User.Query.compose_query({:friends, %User{id: id}}, query)). Previous index on following_relationships.follower_id is just useless (and is removed in this MR) since Postgres can use another existing index on [:follower_id, :following_id] even when there's no condition on following_id in query.

Misc. tweaks: validation improvements in FollowingRelationship.changeset/2.

Note on chosen names for FollowingRelationshipStateEnum values: used :follow_pending, :follow_accept, :follow_reject for the moment for 2 reasons:

  1. such are trivial to auto-replace with other ones should we need that (another benefit compared to hardcoded string values, btw), unlike :accept (atom is already in use in different contexts, so would be slightly harder to rename)

  2. I have plans on merging FollowingRelationship into UserRelationship (IMO it should have been a type of UserRelationship initially but it was developed in parallel). We could either do it converting states to 3 new values in relationship_type (reusing existing index) or moving state as is, as a new integer field in user_relationships (so far leaning towards the latter approach). This way it'd be easier to preload all the relations (follow, mute, block etc.), it would have been done in one query (there are code parts requiring max. optimization of such preloads); also functions like follow_exists?/2 would be defined automatically (by existing code) etc.

Edited Mar 28, 2020 by Ivan Tashkinov
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: following-relationships-optimizations