textpattern / textpattern-default-theme

Textpattern CMS default theme.
https://release-demo.textpattern.co
GNU General Public License v2.0
62 stars 15 forks source link

Monthly archives in the sidebar don't work #41

Closed gocom closed 12 years ago

gocom commented 12 years ago

The "calendar" in the default page template that groups recent articles by month doesn't actually work that well. It will list the publishing months of the latest 12 articles, visible months ranging from 12 to 1. The snippet I'm referring is this:

<!-- using if_different tag to populate list only with months that actually contain articles -->
         <txp:article_custom section="articles" limit="12">
            <txp:if_different>
              <li><a href="<txp:site_url />articles/?month=<txp:posted format="%Y-%m"/>"><span class="archive-year"><txp:posted format="%Y" /></span> <span class="archive-month"><txp:posted format="%b"/></span></a></li>
            </txp:if_different>
          </txp:article_custom>

If a site has 136 articles, posted across 32 month time spawn, and the current month has 12 articles, the sidebar will only list a single month. This is due to the limitactually applying to the query, instead of filtering visible items (which won't be realistically possible). Since the limit is 12 and the month has 12 articles, only one month will be visible (as all the 12 articles have the same month).

Now the obvious would be to increase the limit, but please do not do that - I would avoid that at all costs. Increasing the limit will eat a lot of more resources. The whole if_different listing uses quite a bit of resources, both memory and CPU cycles. For example if the limit is raised to "unlimited" (9999) and the site has 300 articles, Textpattern will first of all fetch 300 rows from the database. This alone takes a while and eats a lot memory. Then if_different will generate 300 MD5 hashes on each page request to filter results (yes, it uses hash comparisons). And that will cost a lot too, way too much actually.

Only feasible solution is to remove the thing completely, I suppose. You can't really increase the limit w/o crashing users' website and with a low limit it shows just a month or two unfortunately. Unless the whole idea is to show just month or two instead of last twelve or so.

philwareham commented 12 years ago

I've been struggling with this one - but more to do with the fact I'm unsure how that whole section would work with languages other than English, and especially with RTL and Asian languages. Your valid comments have sealed it.

So, I agree it should be removed from core. I'll move it to the extras folder which means the code is not lost entirely - some users might find it a useful addition. I will up the limit though to 24 articles so it's more useful.

philwareham commented 12 years ago

Fixed now (removed from core)