y-crdt / ypy-websocket

WebSocket Connector for Ypy
https://davidbrochart.github.io/ypy-websocket
MIT License
42 stars 21 forks source link

Add room storage for Django Channels Consumers #94

Open cacosandon opened 5 months ago

cacosandon commented 5 months ago

This PR introduces a shared storage for consumers within Django Channels.

Initially, each YjsConsumer had its unique YDoc, updating only from its client. This approach caused issues, such as consumers having different YDoc versions that made difficult to update to a persistent storage.

Now, by inheriting from BaseYRoomStorage, a unified storage can be utilized across all consumers and server-wide (e.g., in a Django Celery Job).

The storage's function, detailed in the documentation, is to manage document changes—fetching, updating, and saving them to a single source. An implementation example features Redis for ephemeral and Postgres for permanent storage.

Each user can define their own storage. Maybe using Django Cache, custom Redis or no storage at all (and just use it to broadcast updates from their connected clients). We just define the interface.

I would like to add some tests too 🤔 but not sure how.

zswaff commented 5 months ago

@davidbrochart FYI: @cacosandon has been working on this as a big upgrade to #84 that I worked on a while ago. It is a significant improvement to usability and functionality of using all of this with Django/Channels in my opinion.

It does introduce some breaking changes to the Channels interface (moved the class to a folder, removed one method), but nothing too serious. I already reviewed the work and it works well for our case at Dart.

Would love to support getting this merged however possible, just let me/us know!

davidbrochart commented 5 months ago

Thanks @cacosandon and @zswaff for working on this. Unfortunately ypy is unmaintained, and so is ypy-websocket. I started pycrdt and pycrdt-websocket that are meant to replace them. pycrdt-websocket has the Django Channels Consumer so I think you could make an equivalent PR there. What do you think?

zswaff commented 5 months ago

Makes sense to me! I think this PR will be just as good for that repo.

I didn't know about the change. Are you planning to archive these repos and update the docs to point people to the new ones?

davidbrochart commented 5 months ago

I don't think so, ypy is looking for maintainers.

cacosandon commented 5 months ago

Thanks @zswaff! @davidbrochart, I've just created this same PR in your repository following the library changes.

It works perfect too! https://github.com/jupyter-server/pycrdt-websocket/pull/25