Skip to content

One frontend store with a cache, on api/2 #3429

Todo

Description

@rubenvdlinde

Is your feature request related to a problem? Please describe.

  • Every widget and view calls the API on its own today. A page with four widgets on one table makes four calls for the same data. Proposal P13, with P16 for the api/2 part.
Why this is needed

Describe the solution you'd like

  • One store in the Tables frontend for rows and their sources. It caches collections and items per table or view, shares one request when two widgets ask for the same page, and drops the cache of a source when a row in it is created, updated or deleted. It calls api/2 only.
Diagram
sequenceDiagram
    participant W1 as Data widget
    participant W2 as Stat widget
    participant S as Tables store (new)
    participant API as api/2 rows routes
    W1->>S: page 1 of table 12
    W2->>S: page 1 of table 12
    S->>API: one request
    API-->>S: rows
    S-->>W1: rows from the cache
    S-->>W2: rows from the cache
    W1->>S: update a row
    S->>API: PUT the row
    S->>S: drop cached pages of table 12 and its views
    S-->>W2: refresh
Loading
Acceptance Criteria
  • Collections and single rows are cached per source and per query.
  • Two identical requests in flight lead to one network call.
  • A row change through the store invalidates the cached pages of its table and of the views on it.
  • The store uses api/2 routes only; where a route is missing it is added there first (api/2 routes for capabilities that are internal-only today #3205).
  • Unit tests for the cache, the coalescing and the invalidation.
  • A route added to api/2 for the store declares its permission with #[RequirePermission] using a fixed node type, and the service checks the same right before it writes. A test runs every write as a reader and expects 403 (or 404 where the reader may not know the object exists), as learned in the review of feat(contexts): give applications a menu with its own API #3135.
Components
  • useObjectStore (rewrite, week 44): the store of this issue. Its methods (registerType, fetchSchema, fetchCollection, fetchObject, saveObject, deleteObject, resolveReferences) are rewritten on the api/2 rows and schema routes of Tables, and the per-source cache, the shared request and the invalidation live in it. Every adapt component reaches Tables through it.
Out of scope
  • Subscribing to row events: later, by P13.
  • Moving every component onto the store at once.
  • Slicing, in landing order: one PR for the store with rows, then one PR per consumer, the data widget first, then the table view.

Describe alternatives you've considered

Questions for maintainers

  1. Grow the existing Pinia store src/store/data.js, or add a store beside it? Options: (a) grow data.js, (b) a new store for api/2 and move consumers one by one. We would go with (a): one place knows rows, and consumers do not change their imports.
  2. What happens to the cache when one row changes? Options: (a) drop every cached page of the table and its views, (b) patch the row in every cached page. We would go with (a) for pages and patch the cached single row: (b) cannot know whether the row still matches a page's filter.

Additional context

Linking to other objects
Relevant files:
Related issues

Drafted with AI assistance from the project plan; @remko48 reviews it. Part of #3419.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions