New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using cache in findAndCount and getManyAndCount returns 0 as count #4277
Comments
It seems the problem originates from somewhere in SelectQueryBuilder's getManyAndCount() method.
However, with caching enabled on the query, the counting query is missing from the logs so I assume it does not get executed for some reason and therefore |
Faced a similar issue. This is happening in the getFromCache function when being used with a cache id ( |
Any update on this? |
This comment has been minimized.
This comment has been minimized.
Same, using |
…entity manager functions. Internally TypeOrm is caching query(SELECT DISTINCT ***) when using Repository or Manager functions like find, findAndCount etc…which is leading to return stale data and uncontrolled data invalidation during a mutation. Closes: typeorm#2721, typeorm#5983 typeorm#4277
…entity manager functions. Internally TypeOrm is caching query(SELECT DISTINCT ***) when using Repository or Manager functions like find, findAndCount etc…which is leading to return stale data and uncontrolled data invalidation during a mutation. Closes: typeorm#2721, typeorm#5983 typeorm#4277
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[x]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
cockroachdb
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[ ]
latest
[x]
@next
[x]
0.2.18
Steps to reproduce or a small repository showing the problem:
Consider the following code (the function is inside an abstract class):
Without the cache, the result is fully correct (returns the correct amount of users in the right order, loads the profile relation, correctly paginates and gives back the number of total hits). However when the above is run with caching (as it is specified above) the full result count returns 0.
For example if I have 10 users in my database and I run the query with limit set to 5 and page set to 0, I get 5 users and a count of 0 instead of 10.
The User entity is fairly complex with 11 relations and some other fields, however nothing is eagerly loaded. Some relations have cascade set to true (like the profile the query uses), but removing cascades does not help.
Caching is enabled in ormconfig.js and this issue is present with database cache and ioredis as well.
Also interesting to observe that in the cache, there are 2 queries inserted. One with the 'userBasicList' identifier and one with a NULL identifier. The latter contains a query that starts like this:
Tried using @next, but the same thing happened.
EDIT:
Forgot to mention but the exact same pattern applies when a queryBuilder.getManyAndCount() is used.
The text was updated successfully, but these errors were encountered: