Textpattern CMS support forum

You are not logged in. Register | Login | Help

#41 2010-06-27 08:41:00

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,813
Website

Re: smd_lately: recently viewed site articles

maniqui wrote:

Do you have any idea of what could be going on with this and if there is any measure that could be taken to avoid this issue?

Hmmm, short answer: not sure. Granted the smd_lately tag can be a little heavy because of all the regex stuff going on — it has to exclude a lot of stuff like any potential landing pages, plus it uses 1 query for each result to grab the corresponding article info to allow you to use article tags.

In this case you only use 10 article queries and have 30 days’ worth of results to consider. To dig further we’d have to look at a few more bits of info:

  1. How big the log table is — total number of entries — and roughly how many of those fall in the last 30 days. Consider reducing the size of the log window if possible
  2. How often the smd_lately tag is called — is it every page or only on certain pages? Again, thinning out the density of calls might help
  3. Your tag trace — or at least the query execution time and memory usage info. That might give us a clue of the load on certain pages
  4. Consider wrapping the smd_latey tag in rah_runtime to find out if the lion’s share of total page execution time is actually that tag or something else is contributing
  5. PHP/MySQL version — just for the sake of completeness

One way to circumvent this, which I could perhaps look at implementing, is a cache. If you could somehow control the freshness of the cache using some timeout option — say, 5 minutes — then you could reduce server load at the expense of less up-to-date information and balance it as you see fit. Because of the potentially large nature of the result set I’d probably cache it in a file in the tmp directory instead of the database.

In the meantime you could implement a poor-man’s cache yourself. Untested but something like this in pseudocode:

if ((current time - qui_stored_time ) > 300)
do:
   <txp:smd_lately ... /> : store result in prefs as qui_lately_tag
   Store time() in prefs as qui_stored_time
else: Retrieve qui_lately_tag

Just set qui_stored_time manually with the current time before you start. In fact I’ve just had a thought that perhaps the smd_prefalizer plugin could have a <txp:smd_set_pref> and <txp:smd_get_pref> public-side tags which would facilitate setting this up very easily. I might just do that if it’d help you out (with suitable controls to disallow clobbering TXP’s built-in prefs!) Let me know if this’d be useful.

Alternatively, if you didn’t want to mess about with the prefs directly, you could use smd_vars to stash the stored_time.

Last edited by Bloke (2010-06-27 08:41:44)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#42 2010-06-27 15:07:12

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_lately: recently viewed site articles

Hi Bloke,
many thanks for the thoroughly reply. I’ll investigate the options, probably implementing a cache-based solution (aks_cache) as a quick solution.
BTW, Is there a release of smd_vars?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#43 2010-06-27 15:10:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,813
Website

Re: smd_lately: recently viewed site articles

maniqui wrote:

Is there a release of smd_vars?

Not officially. Could do with one really. One fine day… but hold fire for an hour or so: I’ve updated smd_prefalizer to insert/query prefs from the public side so you can be my guinea pig for that. I’ll drop you a mail once it’s documented.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#44 2010-09-09 12:37:03

jelle
Member
Registered: 2006-06-07
Posts: 165

Re: smd_lately: recently viewed site articles

Hi stef,

Sounds like a great plugin but I just can’t get it to work. Tried regular and zipped version, tried different tags and setting…it just won’t output anything for me.

smd_lately 0.22
txp 4.2
php 5.2

Offline

#45 2010-09-09 12:39:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,813
Website

Re: smd_lately: recently viewed site articles

jelle wrote:

Sounds like a great plugin but I just can’t get it to work. Tried regular and zipped version, tried different tags and setting…it just won’t output anything for me.

Can you please post the tag you’re using? And check you have logging set to All Results and that there are some entries in your Visitor Logs.

Last edited by Bloke (2010-09-09 12:39:41)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#46 2010-09-09 15:16:17

jelle
Member
Registered: 2006-06-07
Posts: 165

Re: smd_lately: recently viewed site articles

Check, check, check
Using just <txp:smd_lately/>
Logging is set to All Results.
Got some entries.

Shall I pm you a login….I’m probably doing something stupid. :)

Offline

#47 2010-09-09 16:36:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,813
Website

Re: smd_lately: recently viewed site articles

jelle wrote:

Check, check, check

OK, cool. Just checking :-)

Using just <txp:smd_lately/>

Right, so that’s only showing results per user. If you’re testing it yourself it should only show articles you’ve visited. It might be worth tring to add by="" just to see if it’s working at all. Also adding debug="2" will show you if there’s any output. If that doesn’t help give some insight into what’s going on, by all means send me a login and I’ll see if I can find out what’s going on.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#48 2010-09-10 11:45:06

jelle
Member
Registered: 2006-06-07
Posts: 165

Re: smd_lately: recently viewed site articles

Hi bloke.

Thanks for pointing out that debug attribute. Gave me some insight to the problem.

This morning, without any changed to my test setup, smd_lately started spitting out articles where yesterday it would just sit there in silence. I’m guessing I have it’s a date/time issue somewhere.

To reproduce I wrote some articles. Clicked on them on the frontend…without result by smd_lately. After pushing back the publish date for the articles with 1 day smd_lately shows them.

My settings for timezone and daylight saving time are all correct. Setting the ‘to’ attribute to a future day didn’t work.
Here’s my debug code

select name from txp_section where 1=1

++ smd_lately RULES ++

array (
  0 => 'page NOT LIKE \'/\'',
  1 => 'page NOT LIKE \'%q=%\'',
  2 => 'page NOT LIKE \'%c=%\'',
  3 => 'page NOT LIKE \'%pg=%\'',
  4 => 'page NOT LIKE \'%category=%\'',
  5 => 'page NOT LIKE \'/category/%\'',
  6 => 'page NOT LIKE \'%author=%\'',
  7 => 'page NOT LIKE \'/author/%\'',
  8 => 'page NOT REGEXP \'^/(aaa|default)/?$\'',
)

SELECT count(page) as popularity, page, MAX(time) as time FROM txp_log WHERE 1=1 AND ip='127.0.0.1' AND page NOT LIKE '/' AND page NOT LIKE '%q=%' AND page NOT LIKE '%c=%' AND page NOT LIKE '%pg=%' AND page NOT LIKE '%category=%' AND page NOT LIKE '/category/%' AND page NOT LIKE '%author=%' AND page NOT LIKE '/author/%' AND page NOT REGEXP '^/(aaa|default)/?$' AND status = 200 GROUP BY page ORDER BY time desc

array (
  0 => 
  array (
    'popularity' => '1',
    'page' => '/textpattern-4.2.0/index.php?id=3',
    'time' => '2010-09-10 13:06:05',
  ),
  1 => 
  array (
    'popularity' => '4',
    'page' => '/textpattern-4.2.0/aaa/test-3',
    'time' => '2010-09-10 12:51:49',
  ),
  2 => 
  array (
    'popularity' => '2',
    'page' => '/textpattern-4.2.0/aaa/test-1',
    'time' => '2010-09-10 12:50:04',
  ),
  3 => 
  array (
    'popularity' => '1',
    'page' => '/textpattern-4.2.0/aaa/test-5',
    'time' => '2010-09-10 12:49:51',
  ),
  4 => 
  array (
    'popularity' => '1',
    'page' => '/textpattern-4.2.0/aaa/test-2',
    'time' => '2010-09-10 12:49:48',
  ),
  5 => 
  array (
    'popularity' => '1',
    'page' => '/textpattern-4.2.0/',
    'time' => '2010-09-10 12:49:34',
  ),
)

select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where url_title='index.php?id=3' AND Posted < CURDATE()

select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where url_title='test-3' AND Posted < CURDATE()

select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where url_title='test-1' AND Posted < CURDATE()

select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where url_title='test-5' AND Posted < CURDATE()

select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where url_title='test-2' AND Posted < CURDATE()

select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where url_title='textpattern-4.2.0' AND Posted < CURDATE()

In the above code all the articles are dated 10th of september except “222” which is dated 9th of september. Only 222 is output by smd_lately. Don’t know how to go on. Is it a bug or maybe a server config issue? Any help is greatly appreciated, really like the functionality of this plugin.

Edited for code display — Stef

Last edited by Bloke (2010-09-10 11:55:02)

Offline

#49 2010-09-10 12:10:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,813
Website

Re: smd_lately: recently viewed site articles

jelle wrote:

I’m guessing I have it’s a date/time issue somewhere.

Yes, sounds like it. I think I may have screwed up. Can you try something for me please? Go into the plugin code and search for CURDATE(). Replace both occurrences with NOW(), save it and see if that improves things. I’ve got a new version waiting to go now, so if that fixes it I’ll issue it today. Thanks.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#50 2010-09-10 12:37:33

jelle
Member
Registered: 2006-06-07
Posts: 165

Re: smd_lately: recently viewed site articles

Great, that did the trick. Thanks!

While I’m at it..here’s an feature request: active_class attribute for the current article when show_current == 1

Thanks again…great plugin.

Offline

Board footer

Powered by FluxBB