Skip to content

Commit

Permalink
Added deduplication for the list guest OS API
Browse files Browse the repository at this point in the history
  • Loading branch information
harikrishna-patnala committed Jan 9, 2023
1 parent 8924a49 commit 13a0c29
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/src/main/java/com/cloud/server/ManagementServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
import com.cloud.utils.db.TransactionCallbackNoReturn;
import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.db.UUIDManager;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.fsm.StateMachine2;
import com.cloud.utils.net.MacAddress;
Expand Down Expand Up @@ -2578,6 +2579,17 @@ public Pair<List<? extends GuestOS>, Integer> listGuestOSByCriteria(final ListGu

if (id != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, id);
} else {
GenericSearchBuilder<GuestOSVO, Long> sb = _guestOSDao.createSearchBuilder(Long.class);
sb.select(null, SearchCriteria.Func.MAX, sb.entity().getId());
sb.groupBy(sb.entity().getCategoryId(), sb.entity().getDisplayName());
sb.done();

final SearchCriteria<Long> scGuestOs = sb.create();
final List<Long> guestOSVOList = _guestOSDao.customSearch(scGuestOs, null);
if (CollectionUtils.isNotEmpty(guestOSVOList)) {
sc.addAnd("id", SearchCriteria.Op.IN, guestOSVOList.toArray());
}
}

if (osCategoryId != null) {
Expand Down

0 comments on commit 13a0c29

Please sign in to comment.