Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

A third batch of refactors to the sync handler #11532

Closed
wants to merge 9 commits into from

Commits on Dec 7, 2021

  1. Pull out _classify_rooms_by_membership_changes

    David Robertson committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    7aee344 View commit details
    Browse the repository at this point in the history
  2. Remove unused branch

    I claim that it is impossible to hit the `continue` which is removed in
    this commit. Setup:
    
    - `events` is a list of all membership events in the range
      `since < time <= now`.
    - `non_joins` is the list of `e in events` with `e.membership` not equal
      to`"join"`.
    - `events` is a nonempty list by construction of
      `mem_change_events_by_room_id`.
    
    Rationale:
    
    - We hit the deleted code only if `non_joins` is empty.
    - If so, `events` consists only of `join` membership events.
    - `events` is non_empty, so there was at least one join during the
      sync period.
    - Therefore the room_id will belong to
      `sync_result_builder.joined_room_ids`. But this means we will have
     `continue`d in the branch above.
      - I'm assuming here that `joined_room_ids` and `events` are both using
       the same `now_token.room_key`.
    David Robertson committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    bca64f9 View commit details
    Browse the repository at this point in the history
  3. Signposting in _classify_rooms_by_membership

    David Robertson committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    7662ba4 View commit details
    Browse the repository at this point in the history
  4. Pull out _fetch_membership_event_at

    Doing so makes it possible we'll repeat a DB query. In the next commit,
    I'll demonstrate that we always call this exactly once.
    David Robertson committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    6ff95ee View commit details
    Browse the repository at this point in the history
  5. Always call old_mem_ev---exactly once.

    I claim this is identical to the existing behaviour. Proof: consider the
    boolean `room_id in sync_result_builder.joined_room_ids or has_join`.
    If this is true, we make the first call to `_fetch_membership_event_at`.
    Otherwise:
    
    - `room_id not in sync_result_builder.joined_room_ids` and `not has_join`.
    - The former means we continue on to inspect `events[-1].membership`.
    - This is not `"join"`, or else `room_id in
      sync_result_builder.joined_room_ids` would be true.
    - `has_join` is False, so we hit the `else` branch and make the second
      call to `_fetch_membership_event_at`.
    
    So, assuming we continue beyond the first `continue`, we always call
    fetch the old membership event exactly once. Do it up front to make the
    reader's life easier.
    David Robertson committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    0d0783c View commit details
    Browse the repository at this point in the history
  6. Remove check on events[-1].membership

    I claim this check is redundant, because said membership cannot be join.
    If not, we'd have `continue`d above because `room_id` would be in
    `sync_result_builder.joined_room_ids`.
    David Robertson committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    a5deabb View commit details
    Browse the repository at this point in the history
  7. Small style rewrite to emphasise exclusive cases

    I prefer `if .. elif` where possible, because I know for sure that at
    most one branch will execute.
    David Robertson committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    50fee89 View commit details
    Browse the repository at this point in the history
  8. Changelog

    David Robertson committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    8bd3565 View commit details
    Browse the repository at this point in the history

Commits on Dec 8, 2021

  1. docstring formatting

    Co-authored-by: Dan Callahan <[email protected]>
    David Robertson and callahad authored Dec 8, 2021
    Configuration menu
    Copy the full SHA
    824ae4e View commit details
    Browse the repository at this point in the history