Skip to content

⚡️perform_update less blocking #2140

Description

@AntoLC

The Problem

Every perform_update call (document save) makes a synchronous, blocking HTTP call to the collaboration server before it can proceed. The same applies to the can_edit endpoint. This means:

  • Every save adds the round-trip latency of the collaboration server
  • If the collaboration server is slow or unreachable, the entire request hangs for up to 10 seconds (the timeout=10)

count, exists = CollaborationService().get_document_connection_info(
document_id,
self.request.session.session_key,
)
except requests.HTTPError as e:

try:
response = requests.get(
endpoint_url, headers=headers, params=querystring, timeout=10
)
except requests.RequestException as e:

Possible solution

We could improve the pattern to be more optimistic, and less blocking.

2 endpoints call _can_user_edit_document:

We could use a cache that last about 15mn:

CAN_EDIT_CACHE_TTL = 60*15
can_edit = self._can_user_edit_document(document.id, set_cache=True)
    cache.set(
        self._can_edit_cache_key(document.id),
        can_edit,
        timeout=CAN_EDIT_CACHE_TTL,
    )
  • If the cache is empty, the requests are blocking so mainly the first time the user try to connect
  • If the cache is not empty, request is unblocking and leaded by the cache, ⚠️ in the same time, we re-trigger a cache update in background (_can_user_edit_document)

Tip

can-edit is usually called before perfom_update by the frontend, increasing the chances that perfom_update will be ever unblocking.

Other way

Note

We could as well imagine a totally different way to save content !

During a save:

  • frontend does a http request on the collaboration server instead of the django server
  • collaboration server check if the condition are respected:
    • user is connected to the collab-server
    • if not if he is alone

Only collaboration server will trigger the save to the django server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions