On Thu, Feb 24, 2011 at 2:20 PM, Chris Withers <ch...@simplistix.co.uk> wrote:
> On 24/02/2011 19:10, Mike Orr wrote:
>>>>
>>>> On Thu, Feb 24, 2011 at 6:37 PM, Mike Orr<sluggos...@gmail.com>  wrote:
>>>>>
>>>>> Paginate works with Pyramid, with the caveat that if you use the
>>>>> Page.pager() method, you have to pass a custom URL generator to the
>>>>> constructor as described on the webhelpers.paginate page.
>
> Okay, I take it the examples that are out there for this still hold true?

The Pyramid example I mentioned in an earlier thread (about a month
ago) should work. I don't have the syntax in front of me. You have to
create a function that returns the correct URL when called like this:

    func(page=4)  =>  /url/for/myarticle?page=4

>>>> So you can use Page.pager(request=request)
>>>
>>> Yep, that was the thought for the next iteration.
>>
>> That's something I hadn't seen, passing a (WebOb-compatible) request
>> to the pager method rather than to the constructor. That might be a
>> solution.
>
> Does that work now or is it something for the future?

Future. The 'request' arg isn't recognized at present.

> What if the primary key is not numeric?

That doesn't matter.

>> to avoid the OFFSET clause which is inefficient (because
>> it has to cycle through all the records before this page).
>
> This I don't follow, lack of relational knowledge.
> I presume you mean the OFFSET is slow on the server?

That's what Ben says. But it's what everybody has been doing, and it's
not slow in my applications.  (MySQL, with a high-grade CPU and plenty
of memory)

>> 1) We can't figure out which record number we're on without cycling
>> through the previous records, because it changes depending on the
>> WHERE clauses.
>
> I don't follow this, can you give a simple example?

Say you have a hundred records numbered 1 to 100, and you're paging
ten at a time. Page 3 is records 20-39, and the number of skipped
records (the OFFSET) is 20 (#1-19).

But if you add arbitrary conditions, like show only records that were
modified on a Thursday and have an address (a relation to another
table), then the offset size will probably be less than 20. But how
much less we don't know unless we run the complete query. So if you
click on a page link

    /article?page=4&last=39

That 'last' doesn't really tell you anything because you still have to
run the whole query to figure out which relative record number you're
at.  (Otherwise ``page.first_item`` and ``page.last_item`` would be
unknown, and you wouldn't be able to say "Showing records 29-39 of
100".)

The only way around that is to pass several more pieces of state data
in the query string, and that's where I worry about miscalculating or
the pages getting out of kilter.

>> 2) The user would have to pass in the name of the primary key field.
>
> To where?

To the Page constructor. It has to know which field to look at to
determine what the last primary key value was.

> Now, anyway, back to the problem at hand for me.
> As it happens, I am looking to paginate the results fairly simple SA query:
>
> session.query(MyModel)
>
> What's the most efficient way I can do that with currently available
> software?
>
> What version of webhelpers should I use? Are there any changes to the query
> I should make to make it more efficient?

Just follow the WebHelpers instructions, and define a URL generator
callback to pass.

WebHelpers 1.2 is the current version and has been stable since last August.

The current code uses OFFSET, but there's no way around that at the
moment. And we're not sure if a more efficient algorithm is feasable
anyway. At least for SQL databases. CouchDB may have its own special
features.

-- 
Mike Orr <sluggos...@gmail.com>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to