You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Note: Currently we only use one global cache for all entities.
6
+
* In the future we probably want a build function that creates a cache and returns the
7
+
* functions (create, update, findMany, …) that use this specific cache.
8
+
*
9
+
* How does it work?
10
+
*
11
+
* We store all decoded entities in a cache and for each query we reference the entities relevant to this query.
12
+
* Whenever a query is registered we add it to the cache and add a listener to the query. Whenever a query is unregistered we remove the listener from the query.
13
+
*/
14
+
typeDecodedEntitiesCache=Map<
15
+
string,// type name
16
+
{
17
+
decoder: (data: unknown)=>unknown;
18
+
type: Any;// TODO should be the type of the entity
19
+
entities: Map<string,Entity<AnyNoContext>>;// holds all entities of this type
20
+
queries: Map<
21
+
string,// instead of serializedQueryKey as string we could also have the actual params
22
+
{
23
+
data: Array<Entity<AnyNoContext>>;// holds the decoded entities of this query and must be a stable reference and use the same reference for the `entities` array
24
+
listeners: Array<()=>void>;// listeners to this query
* Note: Currently we only use one global cache for all entities.
71
-
* In the future we probably want a build function that creates a cache and returns the
72
-
* functions (create, update, findMany, …) that use this specific cache.
73
-
*
74
-
* How does it work?
75
-
*
76
-
* We store all decoded entities in a cache and for each query we reference the entities relevant to this query.
77
-
* Whenever a query is registered we add it to the cache and add a listener to the query. Whenever a query is unregistered we remove the listener from the query.
78
-
*
79
-
* Handling filters is relatively straight forward as they are uniquely identified by their params.
80
-
*
81
-
* Questions:
82
-
* How do we handle findOne?
83
-
* Thoughts: Could be just a special case of findMany limited to a specific id or a separate mechanism.
84
-
* How do we handle relations?
85
-
* Thoughts: We could have a separate query entry for each relation, but when requesting a lot of entities e.g. 1000 only for a nesting one level deep it would result in a lot of cached queries. Not sure this is a good idea.
86
-
*/
87
-
typeDecodedEntitiesCache=Map<
88
-
string,// type name
89
-
{
90
-
decoder: (data: unknown)=>unknown;
91
-
type: Any;// TODO should be the type of the entity
92
-
entities: Map<string,Entity<AnyNoContext>>;// holds all entities of this type
93
-
queries: Map<
94
-
string,// instead of serializedQueryKey as string we could also have the actual params
95
-
{
96
-
data: Array<Entity<AnyNoContext>>;// holds the decoded entities of this query and must be a stable reference and use the same reference for the `entities` array
97
-
listeners: Array<()=>void>;// listeners to this query
0 commit comments