Skip to content

Commit

Permalink
Item12643: fixed caching issue
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/FlexWebListPlugin@17066 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Nov 7, 2013
1 parent 9213c77 commit f091314
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
3 changes: 2 additions & 1 deletion data/System/FlexWebListPlugin.txt
Expand Up @@ -142,11 +142,12 @@ See FlexWebListExamples and FlexWebListTree.
-->

| Plugin Author: | Foswiki:Main.MichaelDaum |
| Copyright ©: | 2006-2012, Michael Daum http://michaeldaumconsulting.com |
| Copyright ©: | 2006-2013, Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: |   |
| 07 Nov 2013: | fixed caching issue |
| 19 Nov 2012: | improve performance on large foswikis by caching a webs iterator to be reused |
| 10 Jan 2012: | fixed setting format strings to the empty string |
| 25 Aug 2011: | added ignorecase paramete; improved documentation |
Expand Down
38 changes: 16 additions & 22 deletions lib/Foswiki/Plugins/FlexWebListPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2006-2012 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2006-2013 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -17,43 +17,37 @@ package Foswiki::Plugins::FlexWebListPlugin;
use strict;
use warnings;

our $VERSION = '1.70';
our $RELEASE = '1.70';
our $VERSION = '1.71';
our $RELEASE = '1.71';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Flexible way to display hierarchical weblists';
our $core;

###############################################################################
sub initPlugin {
sub core {

unless (defined $core) {
require Foswiki::Plugins::FlexWebListPlugin::Core;
$core = new Foswiki::Plugins::FlexWebListPlugin::Core;
}

$core = undef;
return $core;
}

sub initPlugin {

Foswiki::Func::registerTagHandler('FLEXWEBLIST', sub {
return getCore()->handler(@_);
return core->handler(@_);
});

return 1;
}

###############################################################################
sub afterRenameHandler {
my ($oldWeb, $oldTopic, $oldAttachment, $newWeb, $newTopic, $newAttachment) = @_;

return if $oldTopic;

# rename web detected
require Foswiki::Plugins::FlexWebListPlugin::Core;
$Foswiki::Plugins::FlexWebListPlugin::Core::webIterator = undef;
core->reset;
}

###############################################################################
sub getCore {

unless (defined $core) {
require Foswiki::Plugins::FlexWebListPlugin::Core;
$core = new Foswiki::Plugins::FlexWebListPlugin::Core;
}

return $core;
}

1;
27 changes: 14 additions & 13 deletions lib/Foswiki/Plugins/FlexWebListPlugin/Core.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2006-2012 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2006-2013 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -23,7 +23,7 @@ use Foswiki::Meta ();
use Foswiki::WebFilter ();

use constant DEBUG => 0; # toggle me
our $webIterator; # cached version ... invalidated on a web rename
use constant CACHE_WEBS => 1;

###############################################################################
# static
Expand All @@ -35,16 +35,14 @@ sub writeDebug {
# constructor
sub new {
my $class = shift;
my $this = bless({}, $class);

my $this = bless({@_}, $class);

#writeDebug("new FlexWebListPlugin::Core");

$this->{session} = $Foswiki::Plugins::SESSION;
$this->{homeTopic} = Foswiki::Func::getPreferencesValue('HOMETOPIC')
|| $Foswiki::cfg{HomeTopicName} || 'WebHome';

#$webIterator = undef;#DEBUG;

return $this;
}

Expand Down Expand Up @@ -201,6 +199,8 @@ sub formatWeb {

#writeDebug("formatWeb($web->{key})");

my $session = $Foswiki::Plugins::SESSION;

# format all subwebs recursively
my $subWebResult = '';
my @lines;
Expand Down Expand Up @@ -235,7 +235,7 @@ sub formatWeb {

my $url = '';
if ($result =~ /\$url/) {
$url = $this->{session}->getScriptUrl(0, 'view', $web->{key}, $this->{homeTopic});
$url = $session->getScriptUrl(0, 'view', $web->{key}, $this->{homeTopic});
}

my $sitemapUseTo = '';
Expand Down Expand Up @@ -290,14 +290,14 @@ sub formatWeb {
sub getWebIterator {
my $this = shift;

if (defined $webIterator) {
$webIterator->reset;
if (defined $this->{webIterator} && CACHE_WEBS) {
$this->{webIterator}->reset;
} else {
my $webObject = new Foswiki::Meta($this->{session});
$webIterator = $webObject->eachWeb($Foswiki::cfg{EnableHierarchicalWebs});
my @webs = Foswiki::Func::getListOfWebs();
$this->{webIterator} = new Foswiki::ListIterator(\@webs);
}

return $webIterator;
return $this->{webIterator};
}

###############################################################################
Expand All @@ -306,6 +306,7 @@ sub getWebIterator {
sub getWebs {
my ($this, $filter) = @_;

my $session = $Foswiki::Plugins::SESSION;
$filter ||= '';

#writeDebug("getWebs($filter)");
Expand All @@ -324,7 +325,7 @@ sub getWebs {
my $w = '';
$w .= '/' if $w;
$w .= $wit->next();
push @webs, $w if $filter->ok($this->{session}, $w);
push @webs, $w if $filter->ok($session, $w);
}
} else {
@webs = $wit->all();
Expand Down

0 comments on commit f091314

Please sign in to comment.