Skip to content
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

Feature/sort logging #4794

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ public <T> List<T> find(Query query, Class<T> entityClass, String collectionName
Assert.notNull(collectionName, "CollectionName must not be null");
Assert.notNull(entityClass, "EntityClass must not be null");

return doFind(collectionName, createDelegate(query), query.getQueryObject(), query.getFieldsObject(), entityClass,
return doFind(collectionName, createDelegate(query), query.getQueryObject(), query.getFieldsObject(),
query.getSortObject(), entityClass,
new QueryCursorPreparer(query, entityClass));
}

Expand Down Expand Up @@ -899,14 +900,15 @@ <T> Window<T> doScroll(Query query, Class<?> sourceClass, Class<T> targetClass,
operations.getIdPropertyName(sourceClass));

List<T> result = doFind(collectionName, createDelegate(query), keysetPaginationQuery.query(),
keysetPaginationQuery.fields(), sourceClass,
keysetPaginationQuery.fields(), keysetPaginationQuery.sort(), sourceClass,
new QueryCursorPreparer(query, keysetPaginationQuery.sort(), limit, 0, sourceClass), callback);

return ScrollUtils.createWindow(query, result, sourceClass, operations);
}

List<T> result = doFind(collectionName, createDelegate(query), query.getQueryObject(), query.getFieldsObject(),
sourceClass, new QueryCursorPreparer(query, query.getSortObject(), limit, query.getSkip(), sourceClass),
query.getSortObject(), sourceClass,
new QueryCursorPreparer(query, query.getSortObject(), limit, query.getSkip(), sourceClass),
callback);

return ScrollUtils.createWindow(result, query.getLimit(), OffsetScrollPosition.positionFunction(query.getSkip()));
Expand Down Expand Up @@ -2559,8 +2561,8 @@ protected <T> T doFindOne(String collectionName, CollectionPreparer<MongoCollect
* @return the List of converted objects.
*/
protected <T> List<T> doFind(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
Document query, Document fields, Class<T> entityClass) {
return doFind(collectionName, collectionPreparer, query, fields, entityClass, null,
Document query, Document fields, Document sort, Class<T> entityClass) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot simply change the signature of our API. With sort being an essential part for query logging, we might consider reworking QueryCursorPreparer to remove sorting from the preparer and putting it into method signatures.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mp911de - this PR was just to show what is the problem. The easiest way was to show what was incorrectly logged.

return doFind(collectionName, collectionPreparer, query, fields, sort, entityClass, null,
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName));
}

Expand All @@ -2579,21 +2581,21 @@ protected <T> List<T> doFind(String collectionName, CollectionPreparer<MongoColl
* @return the {@link List} of converted objects.
*/
protected <T> List<T> doFind(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
Document query, Document fields, Class<T> entityClass, CursorPreparer preparer) {
return doFind(collectionName, collectionPreparer, query, fields, entityClass, preparer,
Document query, Document fields, Document sort, Class<T> entityClass, CursorPreparer preparer) {
return doFind(collectionName, collectionPreparer, query, fields, sort, entityClass, preparer,
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName));
}

protected <S, T> List<T> doFind(String collectionName,
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query, Document fields,
Class<S> entityClass, @Nullable CursorPreparer preparer, DocumentCallback<T> objectCallback) {
Document sort, Class<S> entityClass, @Nullable CursorPreparer preparer, DocumentCallback<T> objectCallback) {

MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);

QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
Document mappedFields = queryContext.getMappedFields(entity, EntityProjection.nonProjecting(entityClass));
Document mappedQuery = queryContext.getMappedQuery(entity);
Document mappedSort = getMappedSortObject(query, entityClass);
Document mappedSort = getMappedSortObject(sort, entityClass);

if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("find using query: %s fields: %s sort: %s for class: %s in collection: %s",
Expand Down