Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#193 2017-03-20 08:35:55

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: etc_pagination: paginate everything

I think you need to create a cache block per page:

<txp:etc_cache id='archives-<txp:page_url type="pg" />' reset="article_posted,articles_deleted">
<!-- code -->
</txp:etc_cache>

But, since you have many articles, auto-updating will take some time.

Edit: that’s not a very good idea, though, because pg is set by site visitors. A bad guy bombarding your site with ...&pg=666 requests would quickly overfill the cache table. Probably, <txp:page_url type="pg" /> should be limited by some reasonable value.

Offline

#194 2017-03-20 08:52:47

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

etc wrote #304922:

I think you need to create a cache block per page:
<txp:etc_cache id='archives-<txp:page_url type="pg" />' reset="article_posted,articles_deleted">...

That seems to have solved it, thank you!

But, since you have many articles, auto-updating will take some time.

Where/how will I notice the updating “taking time”?

…Probably, <txp:page_url type="pg" /> should be limited by some reasonable value.

Thank you very much for this too! I’ll set the limit in the etc_pagination tag, yes?


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#195 2017-03-20 09:07:43

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: etc_pagination: paginate everything

alicson wrote #304925:

Where/how will I notice the updating “taking time”?

When you will publish a new article or delete an existing one. Set as above, etc_cache will try to update the cache for each page, and this can take time.

Thank you very much for this too! I’ll set the limit in the etc_pagination tag, yes?

You are already counting the articles with etc_query, right? Try to reuse the counter variable somehow. ;-)

Offline

#196 2017-03-20 09:26:34

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

etc wrote #304927:

You are already counting the articles with etc_query, right? Try to reuse the counter variable somehow. ;-)

Is that where I set the limit—within the etc_query? Or elsewhere? (I really appreciate your patience.)


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#197 2017-03-20 10:37:01

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: etc_pagination: paginate everything

No worries, I enjoy txp challenges. You can count pages with etc_pagination, but it would take an extra db query. Let’s try another way.

From a quick look at your page, the monthly archive is constructed before the main content? So, right after this block, <txp:variable name="counter" /> stores the total number of live articles from journal,briefs,about,words sections. The first invalid page number can be calculated and stored in <txp:variable name="nopage" /> with

<txp:etc_query name="nopage" data="{?counter|1|/200.intval.+2}" />

Now, replace (wherever needed) <txp:page_url type="pg" /> with

<txp:etc_query data='<txp:page_url type="pg" />' query="$min($|{?nopage}).max($|0)" />

to limit pg to nopage.

Offline

#198 2017-03-20 18:47:12

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

I would not have come up with that on my own >_< I think I’m absorbing the syntax and the concepts though. Thank you again. !
<txp:page_url type="pg" /> goes in the id of etc_cache, yes? So then I have a double-nested txp tag, and I think that’s what my page was balking at? So I made another variable:

<txp:variable name="pglimit"><txp:etc_query data='<txp:page_url type="pg" />' query="$min($|{?nopage}).max($|0)" /></txp:variable>

<txp:etc_cache id='dense_archivebydate<txp:variable name="pglimit" />'>

Seems to be working..was this right? Or what’s the proper/better way to do this?


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#199 2017-03-20 20:25:49

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: etc_pagination: paginate everything

alicson wrote #304945:

<txp:page_url type="pg" /> goes in the id of etc_cache, yes? So then I have a double-nested txp tag, and I think that’s what my page was balking at? So I made another variable:

<txp:variable name="pglimit"><txp:etc_query data='<txp:page_url type="pg" />' query="$min($|{?nopage}).max($|0)" /></txp:variable>

That’s fine, though you can shorten it to

<txp:etc_query name="pglimit" data='<txp:page_url type="pg" />' query="$min($|{?nopage}).max($|1)" />

You can also simply use nested quotes:

txp <txp:etc_cache id='dense_archivebydate<txp:etc_query data=''<txp:page_url type="pg" />'' query="$min($|{?nopage}).max($|1)" />'>

Seems to be working..was this right? Or what’s the proper/better way to do this?

Ahem… does not seem to work on your site atm, but you are probably tweaking something? A more straightforward way is to directly modify txp internals instead of nopage and pglimit calculation:

<txp:php>
    global $pretext, $variable;
    $pretext['pg'] = max(1, min(intval($variable['counter']/200) + 2, $pretext['pg']));
</txp:php>

Then <txp:page_url type="pg" /> will be limited, so you can safely call

<txp:etc_cache id='dense_archivebydate<txp:page_url type="pg" />'>

But internals can change one day.

Offline

#200 2017-03-20 21:02:46

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

re: etc wrote #304947

Ooh double single quotes. That’s new for me.

For my own sense, is there a reason why an enduser (spam) can make up page numbers and slam the site that way? Or does it generally just not matter, except when one happens to have combinations of pagination and caching set up without having further accounted for queries of miscellaneous imaginary page numbers?

And what do the .max($|0) vs. the .max($|1) mean?

Thank you!


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#201 2017-03-20 21:10:34

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

And yes it seems to be frozen again.

I have

<txp:variable name="numPgs"><txp:etc_numpages section="journal,briefs,about,words" pageby="500" /></txp:variable>
<txp:variable name="nopage"><txp:etc_query name="nopage" data="{?numPgs|1|/500.intval.+2}" /></txp:variable>

and

<txp:etc_cache id='dense_archivebydate<txp:etc_query data=''<txp:page_url type="pg" />'' query="$min($|{?nopage}).max($|1)" />'>


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#202 2017-03-20 21:24:05

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: etc_pagination: paginate everything

You divide by 500 twice. Try

<txp:variable name="numPgs" value='<txp:etc_numpages section="journal,briefs,about,words" pageby="500" />' />
<txp:etc_query name="nopage" data="{?numPgs|1|.+1}" />

Offline

#203 2017-03-20 21:39:23

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: etc_pagination: paginate everything

alicson wrote #304948:

For my own sense, is there a reason why an enduser (spam) can make up page numbers and slam the site that way? Or does it generally just not matter, except when one happens to have combinations of pagination and caching set up without having further accounted for queries of miscellaneous imaginary page numbers?

I’m not a behavioral specialist, sorry. :-) In general it does not matter, but in your case etc_cache will create a record for every encountered (even invalid) pg value and try to update it later. This will take unnecessary time and space.

And what do the .max($|0) vs. the .max($|1) mean?

Zero was a mistype, sorry. .max($|1) means for etc_query the maximum between 1 and the initial data passed by the chain:

<txp:etc_query data="2" query="$*2.+1.max($|3)" />

reads as 2 -> 2*2=4 -> 4+1=5 -> max(5, 3)=5.

Offline

#204 2017-03-20 21:49:53

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: etc_pagination: paginate everything

I didn’t mean human-behavior-wise, I meant the structure of the site allowing for calls to imaginary pages that can cause a problem. ;) Sounds like the answer is the “create a record for every encountered (even invalid) pg value”.

Ahh txp:etc_query can assign like txp:variable; no wonder.
I think it’s good to go now, again with much thanks :)


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

Board footer

Powered by FluxBB