VisitorPlugin

VisitorPlugin

Postby samoht on Mon Apr 30, 2007 7:41 am

I'v tryed to piece together a plugin that shows the last 5 visitors to your blog. If someone would like to try it out and help me improve it (bugtest) i would be grateful :)

url to the zip file : http://stud.aitel.hist.no/~thomaser/visit.zip

-Thomas
If you think you can, you can. And if you think you can't, you're right.
samoht
 
Posts: 3
Joined: Mon Apr 30, 2007 7:28 am

Postby phunkphorce on Mon Apr 30, 2007 8:13 am

Just one question, how are you planning to address caching issue? I noticed that you're relying on the EVENT_POST_LOADED event, but the problem is that this event is only generated once when the post is loaded, and if the template is cached, no more events are generated the next time the page is loaded.

You should also keep in mind that EVENT_POST_LOADED is also generated from the admin interface, so you should make sure that you're ignoring the event in that situation. I think there is a parameter called "source" or "class" or something like that in the $params array that you use in the PluginBase::process() method, which contains the name of the class that generated the event. Take a look at it (or just add print_r($params) in your process() method to see what you get...)
phunkphorce
Lifetype Expert
 
Posts: 9028
Joined: Mon Aug 25, 2003 6:34 am
Location: Suomessa

Postby samoht on Mon Apr 30, 2007 8:29 am

I am not using events, it's juste some code that i forgot do remove.
The caching tho would still be a problem. But a friend of mine told me that if I use the {dynamic} option in smarty this would no longer be a problem.
If you think you can, you can. And if you think you can't, you're right.
samoht
 
Posts: 3
Joined: Mon Apr 30, 2007 7:28 am

Postby phunkphorce on Mon Apr 30, 2007 8:51 am

I'm not sure about the {dynamic} thingie, have you tried it yet?
phunkphorce
Lifetype Expert
 
Posts: 9028
Joined: Mon Aug 25, 2003 6:34 am
Location: Suomessa

Postby samoht on Mon Apr 30, 2007 9:28 am

does not look like the plugin can be used inside the {dynamic} tags.. so if the site-cache is enabled this plugin would not work as intended.
If you think you can, you can. And if you think you can't, you're right.
samoht
 
Posts: 3
Joined: Mon Apr 30, 2007 7:28 am

Postby evens83 on Mon Apr 30, 2007 9:40 am

samoht wrote:does not look like the plugin can be used inside the {dynamic} tags.. so if the site-cache is enabled this plugin would not work as intended.



I searched trough earlier posts on this forum. And one of the post where saying that the {dynamic}-tag in Smarty doesn't support dynamic updates that relies on objects like: $user, $posts...

Is this correct? Because if it is, then that may be the root of the problem he in facing. But isn't it possible to make some changes to the core of Lifetype, so as to make this possible?
evens83
 
Posts: 15
Joined: Mon Feb 12, 2007 11:12 am

Postby phunkphorce on Mon Apr 30, 2007 12:26 pm

Smarty will display anything placed in the {dynamic} tags as long as it's been previously loaded.

In LT, if a template is cached then very little is done and loaded because basically, all the information that had to be displayed in the template was already displayed when the template was first rendered and cached, so there is no need to load things like plugins, or data, or whatever. Support for {dynamic} blocks was added to address a very specific issue (loading the user data from the session to get it displayed in the "add comment" form) an other than that, its applications are very limited in scope.

If your template depends on some dynamic data regardless of whether it's cached or not, I would suggest using Javascript (ajax) to solve this issue. Just make the template call a special URL that will return a value that can then be placed back somewhere in the page. It shouldn't be too difficult to do using ajax and dhtml.
phunkphorce
Lifetype Expert
 
Posts: 9028
Joined: Mon Aug 25, 2003 6:34 am
Location: Suomessa

Postby jondaley on Mon Apr 30, 2007 3:46 pm

Plugins aren't loaded when the template is cached, so plugins can't be used inside {dynamic} tags. I have been wondering about adding either a checkbox in the admin that says load plugins during cached views, or if the plugins could report whether or not it is useful for them to be called in that instance, and then they would only be loaded for people who use them, and not slow down everyone else.

But, I haven't figured out the best way to do that.
jondaley
Lifetype Expert
 
Posts: 6169
Joined: Thu May 20, 2004 6:19 pm
Location: Pittsburgh, PA, USA
LifeType Version: 1.2.11 devel branch

Postby evens83 on Tue May 01, 2007 9:37 am

jondaley wrote:Plugins aren't loaded when the template is cached, so plugins can't be used inside {dynamic} tags. I have been wondering about adding either a checkbox in the admin that says load plugins during cached views, or if the plugins could report whether or not it is useful for them to be called in that instance, and then they would only be loaded for people who use them, and not slow down everyone else.

But, I haven't figured out the best way to do that.


I've been doing some researching on this case now. And I actually can't understand the reason why you are disabling access to plugins when templates are cached? Is it because of the overhead it is adding to the system?

I tried, as an experiment, to enable loading of plugins when templates is already cached. And I tried to measure the "performance slowdown" it's causing. This was measured using the PHP-function microtime(). And what I found, was that it didn't put much stress to the system. I also tried to install every available plugins to my plugin-folder, and that didn't seem to increase the load either.

The file that I played with, is: "...class/view/blogview.class.php", and I'm referring to the function named render().

Code: Select all
...
function render() {
  if( !$this->isCached() ) {
    ...
    $this->setValue( 'archives', $this->_getArchives());
    ...
    // also, let's not forget about the plugins...
    // put the plugins in the context
    $plugins = $this->_pm->getPlugins();
    foreach( $plugins as $name => $plugin ) {
      $this->setValue( $name, $plugin );
    }
}


I can see the reason why you are doing the setValue('archives') only when the template isn't cached. Because that's an expensive call measured by an performance point of view, since that function is actually executing a sql-query.

But on the other hand. The the code above which is loading the plugins isn't doing any expensive job as I can see, as it's just "presenting" the plugins-variables to the templates.
evens83
 
Posts: 15
Joined: Mon Feb 12, 2007 11:12 am

Postby phunkphorce on Tue May 01, 2007 11:03 am

We need to investigate if that's the case but if it really is, we won't be able to change it until LT 1.3. Otherwise we'd be breaking compatibility for plugins accross the 1.2.x branch (and that's something we wouldn't like to do)
phunkphorce
Lifetype Expert
 
Posts: 9028
Joined: Mon Aug 25, 2003 6:34 am
Location: Suomessa


Return to Plugin Development Team

cron