Pagination and query limits

98 views
Skip to first unread message

JM Talarovich

unread,
Oct 22, 2015, 9:44:32 AM10/22/15
to CFWheels
Is there a way to limit the total record count of a query when using CFWheels pagination?  Pagination works great even when a search returns 6000 records... but if a search returns say 10000 records it spins.  I just want to limit the max number of records a query returns while still using pagination.

Tom King

unread,
Oct 22, 2015, 9:48:29 AM10/22/15
to cfwh...@googlegroups.com
I thought wheels just did COUNT() to get the total possible records (as opposed to retrieving the actual records?)

Even so, this might be worth a go:

foo=model(“bar”).findAll(count=5000, perpage=50, page=1);

(from the docs:

When using pagination and you know in advance how many records you want to paginate through, you can pass in that value here. Doing so will prevent Wheels from running aCOUNT query to get this value. This argument is only used when the page argument has been passed in. )

T

On 22 Oct 2015, at 14:44, JM Talarovich <jmtala...@gmail.com> wrote:

Is there a way to limit the total record count of a query when using CFWheels pagination?  Pagination works great even when a search returns 6000 records... but if a search returns say 10000 records it spins.  I just want to limit the max number of records a query returns while still using pagination.

--
You received this message because you are subscribed to the Google Groups "CFWheels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwheels+u...@googlegroups.com.
To post to this group, send email to cfwh...@googlegroups.com.
Visit this group at http://groups.google.com/group/cfwheels.
For more options, visit https://groups.google.com/d/optout.

Chris Peters

unread,
Oct 22, 2015, 10:10:51 AM10/22/15
to cfwh...@googlegroups.com
Can you show some of the offending code? If you're using page/perPage, then it should be limiting the number of records returned from the database.

You should also be able to use the pagination() function to get stats like totalRecords without CF needing to get every single record from the table:
http://docs.cfwheels.org/v1.4/docs/pagination

On Thu, Oct 22, 2015 at 9:44 AM, JM Talarovich <jmtala...@gmail.com> wrote:
Is there a way to limit the total record count of a query when using CFWheels pagination?  Pagination works great even when a search returns 6000 records... but if a search returns say 10000 records it spins.  I just want to limit the max number of records a query returns while still using pagination.

--
You received this message because you are subscribed to the Google Groups "CFWheels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfwheels+u...@googlegroups.com.
To post to this group, send email to cfwh...@googlegroups.com.
Visit this group at http://groups.google.com/group/cfwheels.
For more options, visit https://groups.google.com/d/optout.



--

Chris Peters
Web Developer
Liquifusion Studios

chris....@liquifusion.com
Skype: liquifusion.support
www.liquifusion.com

JM Talarovich

unread,
Oct 25, 2015, 9:13:22 PM10/25/15
to CFWheels
@tom, I tried that but what I did like was that if the search returned less than what you set as 'count'  there still would be pagination links going all the way to 'count'.  which was a pretty weird behavior.

@chris, it seemed to work fine with small queries, but seemed to break on large resultsets.

Regardless, for me what ended up being the winning ticket was to use setPagination using a custom query.  I can set my limit in the custom query then pass it all to setPagination as such:

<cfset setPagination(totalRecords=local.customQuery.RecordCount, currentPage=arguments.page, perPage=arguments.perPage, handle="myCustomQueryHandle")>

Thanks for the great documentation for setPagination()!!!
Reply all
Reply to author
Forward
0 new messages