joist-orm / joist-orm/joist-orm

Non-Persisted Derived Properties can cause Over Reactivity

Open
#625 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
385
Forks
26
Avg merge
8h 55m
Merged PRs (30d)
42

Description

Given a model like:

- Entities of `Author`, `Book`, `BookReview`
- `Book.mostRecentReview` is an `hasReactiveAsyncProperty` that loads all N of its `BookReview`s, returns the latest `BookReview`
- `Author.mostRecentBookReviewText` is a `hasPersistedAsyncProperty` that loads `{ books: "mostRecentReview" }` to pick the latest book's, latest's reviews text

The reversed hints/reactivity infra will then:

- Any time `BookReview.text` changes, we will `em.touch` the review's book's `Author` (and reload all books + all book reviews to re-calc `Author.mostRecentBookReviewTest`), even if this `BookReview` is not the latest review

Note that if `Book.mostRecentReview` was itself a `hasPersistedAsyncProperty`, then b/c we know both the old value/new value, then the more selective reactivity would work, b/c the revered hint would be able to use `BookReview -> book.most_recent_review_id` FK/m2o to only crawl up from `BookReview` to `Book` for `BookReview`s that are actually the most recent `BookReview`.

(...granted we don't support persisted derived FKs yet...).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.