Conversation
|
What's the status on this? Could an Elixir dev review the implementation? |
|
Bit confusing since the interruptible shapes pr was based off it and has now been merged so this is showing both sets. This is the real pr: Most of the real work was done in the elixir client -- this pr mostly cleans up the shape definition path in phoenix.sync, so that it does less work when defining shapes and uses the client for the heavy lifting. should hopefully remove the need to change the shape definition api in 3 places when it evolves. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive support for changeset shapes in Phoenix.Sync, enabling shapes to be defined using Ecto changeset functions alongside existing table and query-based definitions. It also refactors the shape definition path to remove Phoenix.Sync from the chain of shape understanding components, allowing client shape changes to propagate to Phoenix.Sync without requiring changes to the sync system itself.
- Adds changeset function support for defining shapes from Ecto schemas with validation
- Implements interruptible shape requests that can be dynamically updated during long-polling
- Refactors PredefinedShape to use Electric.Client.ShapeDefinition for better separation of concerns
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| test/support/todo.ex | Updates changeset function to provide default struct parameter |
| test/support/controllers/todo_controller.ex | Adds controller endpoints demonstrating changeset and interruptible shapes |
| test/phoenix/sync_test.exs | Adds comprehensive tests for shape interruption functionality |
| test/phoenix/sync/router_test.exs | Tests parameterized where clauses in router definitions |
| test/phoenix/sync/predefined_shape_test.exs | New test file for comprehensive PredefinedShape functionality |
| test/phoenix/sync/controller_test.exs | Tests changeset support and interruptible request handling |
| test/phoenix/sync/client_test.exs | Tests Ecto query support with additional shape options |
| test/phoenix/sync/application_test.exs | Minor cleanup of storage path assertions |
| lib/phoenix/sync/shape_request_registry.ex | New registry for managing interruptible shape requests |
| lib/phoenix/sync/predefined_shape.ex | Major refactor to use Electric.Client.ShapeDefinition |
| lib/phoenix/sync/electric/client_adapter.ex | Updates client adapter for new shape handling |
| lib/phoenix/sync/controller.ex | Adds comprehensive interruptible request support |
| lib/phoenix/sync/client.ex | Simplifies shape resolution using PredefinedShape |
| lib/phoenix/sync/application.ex | Adds ShapeRequestRegistry to supervision tree |
| lib/phoenix/sync.ex | Adds interrupt/2 and shape!/2 public API functions |
and clean up the shape definition path, removing phoenix.sync from the chain of "things that understand shapes" so now if you change the client's view of a shape it should propagate to phoenix.sync without changes
When building shape params on the server, for example using `sync_render`, it's useful to be able to respond to database changes that would cause the shape params to be different. For example, `/sync/projects` -> looks up posts for user, syncs `where id IN $userProjectIds`. Then the user joins another thread. Now, ... at the moment, this can wait until 20s for a long poll to return before the /sync/projects controller code runs to reconstruct the new shape params with the new where clause. What this PR does is provide a `Phoenix.Sync.interrupt(Projects.Project)` function that other backend code can call in order to interrupt current long polling requests. This is similar to using the abort controller with the javascript client. --------- Co-authored-by: Garry Hill <garry@magnetised.net>
6562564 to
2189a83
Compare
conflicts here we come
Also clean up the shape definition path, removing Phoenix.Sync from the chain of "things that understand shapes" so now if you change the client's view of a shape it should propagate to Phoenix.Sync without changes