You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Anurag Awasthi <An...@shapeblue.com> on 2019/07/01 04:13:35 UTC
Question about GenericDaoBase#searchAndCount method
Hi Devs,
I was looking at a bug and observed that In GenericDaoBase.java#searchAndCount we have the following function -
public Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc, final Filter filter) {
List<T> objects = search(sc, filter, null, false);
Integer count = getCount(sc);
// Count cannot be less than the result set but can be higher due to pagination, see CLOUDSTACK-10320
if (count < objects.size()) {
count = objects.size();
}
return new Pair<List<T>, Integer>(objects, count);
}
Internally the getCount above ignores the Group By parts of Search Query to retrieve count. It could result in the List and Count being returned as different. Perhaps some documentation is missing here. Does anyone know why we have this logic?
Regards,
Anurag
Anurag.Awasthi@shapeblue.comĀ
www.shapeblue.com
Amadeus House, Floral Street, London WC2E 9DPUK
@shapeblue
Re: Question about GenericDaoBase#searchAndCount method
Posted by Daan Hoogland <da...@gmail.com>.
the count in the fragment has an obvious trivial bug: it counts objects
while one of the objects is the actual count.
it should read
```
if (count < (objects.size() - 1)) {
count = objects.size() - 1;
}
```
On Mon, Jul 1, 2019 at 10:57 AM Rohit Yadav <ro...@shapeblue.com>
wrote:
> In some cases where the response is being paginated, the count would
> represent the total number of resources while the size of the returned
> array/list of resources would be less.
>
>
> Regards,
>
> Rohit Yadav
>
> Software Architect, ShapeBlue
>
> https://www.shapeblue.com
>
> ________________________________
> From: Anurag Awasthi <An...@shapeblue.com>
> Sent: Monday, July 1, 2019 9:43:35 AM
> To: dev@cloudstack.apache.org
> Subject: Question about GenericDaoBase#searchAndCount method
>
> Hi Devs,
>
> I was looking at a bug and observed that In
> GenericDaoBase.java#searchAndCount we have the following function -
>
> public Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc,
> final Filter filter) {
> List<T> objects = search(sc, filter, null, false);
> Integer count = getCount(sc);
> // Count cannot be less than the result set but can be higher due
> to pagination, see CLOUDSTACK-10320
> if (count < objects.size()) {
> count = objects.size();
> }
> return new Pair<List<T>, Integer>(objects, count);
> }
>
> Internally the getCount above ignores the Group By parts of Search Query
> to retrieve count. It could result in the List and Count being returned as
> different. Perhaps some documentation is missing here. Does anyone know why
> we have this logic?
>
> Regards,
> Anurag
>
> Anurag.Awasthi@shapeblue.com
> www.shapeblue.com<http://www.shapeblue.com>
> Amadeus House, Floral Street, London WC2E 9DPUK
> @shapeblue
>
>
>
>
> rohit.yadav@shapeblue.com
> www.shapeblue.com
> Amadeus House, Floral Street, London WC2E 9DPUK
> @shapeblue
>
>
>
>
--
Daan
Re: Question about GenericDaoBase#searchAndCount method
Posted by Rohit Yadav <ro...@shapeblue.com>.
In some cases where the response is being paginated, the count would represent the total number of resources while the size of the returned array/list of resources would be less.
Regards,
Rohit Yadav
Software Architect, ShapeBlue
https://www.shapeblue.com
________________________________
From: Anurag Awasthi <An...@shapeblue.com>
Sent: Monday, July 1, 2019 9:43:35 AM
To: dev@cloudstack.apache.org
Subject: Question about GenericDaoBase#searchAndCount method
Hi Devs,
I was looking at a bug and observed that In GenericDaoBase.java#searchAndCount we have the following function -
public Pair<List<T>, Integer> searchAndCount(final SearchCriteria<T> sc, final Filter filter) {
List<T> objects = search(sc, filter, null, false);
Integer count = getCount(sc);
// Count cannot be less than the result set but can be higher due to pagination, see CLOUDSTACK-10320
if (count < objects.size()) {
count = objects.size();
}
return new Pair<List<T>, Integer>(objects, count);
}
Internally the getCount above ignores the Group By parts of Search Query to retrieve count. It could result in the List and Count being returned as different. Perhaps some documentation is missing here. Does anyone know why we have this logic?
Regards,
Anurag
Anurag.Awasthi@shapeblue.com
www.shapeblue.com<http://www.shapeblue.com>
Amadeus House, Floral Street, London WC2E 9DPUK
@shapeblue
rohit.yadav@shapeblue.comĀ
www.shapeblue.com
Amadeus House, Floral Street, London WC2E 9DPUK
@shapeblue