Skip to content

Commit

Permalink
fix: Scrolling a Column in Board View crashes when fetching further I…
Browse files Browse the repository at this point in the history
…ssues from Server (OD-2078)
  • Loading branch information
robinshine committed Sep 18, 2024
1 parent 5f6db38 commit 9ec7fc7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,7 @@ private void applyOrders(From<Build, Build> root, CriteriaQuery<?> criteriaQuery
else
orders.add(builder.desc(BuildQuery.getPath(root, Build.ORDER_FIELDS.get(sort.getField()))));
}

if (orders.isEmpty())
orders.add(builder.desc(root.get(Build.PROP_ID)));
addOrderByIdIfNecessary(builder, root, orders);
criteriaQuery.orderBy(orders);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ private CriteriaQuery<CodeComment> buildCriteriaQuery(Project project, Session s

if (orders.isEmpty())
orders.add(builder.desc(CodeCommentQuery.getPath(root, CodeComment.PROP_LAST_ACTIVITY + "." + LastActivity.PROP_DATE)));
addOrderByIdIfNecessary(builder, root, orders);
query.orderBy(orders);

return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ public List<javax.persistence.criteria.Order> buildOrders(List<EntitySort> sorts
if (orders.isEmpty())
orders.add(builder.desc(IssueQuery.getPath(issue, Issue.PROP_LAST_ACTIVITY + "." + LastActivity.PROP_DATE)));

addOrderByIdIfNecessary(builder, issue, orders);

return orders;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,8 @@ private CriteriaQuery<Project> buildCriteriaQuery(Session session, EntityQuery<P

if (orders.isEmpty())
orders.add(builder.asc(root.get(Project.PROP_PATH_LEN)));
addOrderByIdIfNecessary(builder, root, orders);

query.orderBy(orders);

return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ private CriteriaQuery<PullRequest> buildCriteriaQuery(Session session, @Nullable

if (orders.isEmpty())
orders.add(builder.desc(PullRequestQuery.getPath(root, PullRequest.PROP_LAST_ACTIVITY + "." + LastActivity.PROP_DATE)));

addOrderByIdIfNecessary(builder, root, orders);
query.orderBy(orders);

return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

import io.onedev.server.model.AbstractEntity;
import io.onedev.server.util.ReflectionUtils;
import org.hibernate.query.criteria.internal.path.SingularAttributePath;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Order;

public abstract class BaseEntityManager<T extends AbstractEntity> implements EntityManager<T> {

Expand Down Expand Up @@ -93,4 +98,17 @@ public Class<T> getEntityClass() {
return entityClass;
}

protected void addOrderByIdIfNecessary(CriteriaBuilder builder, From<?, ?> from, List<Order> orders) {
boolean orderByIdFound = false;
for (var order: orders) {
if (order.getExpression() instanceof SingularAttributePath
&& ((SingularAttributePath) order.getExpression()).getAttribute().getName().equals(AbstractEntity.PROP_ID)) {
orderByIdFound = true;
break;
}
}
if (!orderByIdFound)
orders.add(builder.desc(from.get(AbstractEntity.PROP_ID)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ public Iterator<? extends Issue> iterator(long first, long count) {
try {
var query = queryModel.getObject();
if (query != null) {
return getIssueManager().query(getProjectScope(), (IssueQuery) query,
return getIssueManager().query(getProjectScope(), query,
true, (int) first, (int) count).iterator();
}
} catch (ExplicitException e) {
Expand Down

0 comments on commit 9ec7fc7

Please sign in to comment.