Description
I use Javers (5.12.0) with MongoDB repository in a production environment for auditing one object with one child.
Currently the snapshots collection contains more than 1 millions documents and we meet performance issue when finding changes by instanceId with child value object :
QueryBuilder queryBuilder = QueryBuilder.byInstanceId(orderId,OrderAudit.class).withNewObjectChanges().withChildValueObjects(); Changes changes = javers.findChanges(queryBuilder.build());
This request takes about 4 seconds to get results.
After debugging,it appears that "withChildValueObjects()" option will generate a regex filter in MongoRepository to retreive child objects:
{"find": "jv_snapshots", "filter": {"$or": [{"globalId_key": "OrderAudit/1818342"}, {"globalId_key": {"$regularExpression": {"pattern": "^OrderAudit/1818342#.*", "options": ""}}}]}, "sort": {"commitMetadata.id": -1}, "limit": 100, "$db": "javers-audit"}
As we can see the query do a filter on exact globalId_key ( very fast as there is an index for this property in Mongo DB ) but the second part with regex filter is very slow.
Have you already see this issue ?
Is there any solution to solve this ?
May be we could filter using globalID.ownerId property ?
"globalId": { "valueObject": "OrderAuditChild", "ownerId": { "entity": "OrderAudit", "cdoId": 1818031 }, "fragment": "child" }
Thanks in advance for your help :)
BR