← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:09 2015

Filename/var/www/foswiki11/lib/Foswiki/Prefs.pm
StatementsExecuted 13797 statements in 30.7ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
717211110.5ms17.7msFoswiki::Prefs::::getPreferenceFoswiki::Prefs::getPreference
679119.28ms8.27sFoswiki::Prefs::::loadPreferencesFoswiki::Prefs::loadPreferences
446115.24ms8.22sFoswiki::Prefs::::_getWebPrefsObjFoswiki::Prefs::_getWebPrefsObj
123713.07ms9.69sFoswiki::Prefs::::_getBackendFoswiki::Prefs::_getBackend
91112.20ms8.21sFoswiki::Prefs::::_pushWebInStackFoswiki::Prefs::_pushWebInStack
1111.58ms4.10msFoswiki::Prefs::::finishFoswiki::Prefs::finish
125721.11ms1.11msFoswiki::Prefs::::setInternalPreferencesFoswiki::Prefs::setInternalPreferences
1111.06ms1.32msFoswiki::Prefs::::BEGIN@70Foswiki::Prefs::BEGIN@70
722624µs7.33msFoswiki::Prefs::::pushTopicContextFoswiki::Prefs::pushTopicContext
611371µs3.65msFoswiki::Prefs::::popTopicContextFoswiki::Prefs::popTopicContext
111370µs412µsFoswiki::Prefs::::BEGIN@71Foswiki::Prefs::BEGIN@71
711367µs1.30sFoswiki::Prefs::::setPluginPreferencesFoswiki::Prefs::setPluginPreferences
111312µs805µsFoswiki::Prefs::::BEGIN@69Foswiki::Prefs::BEGIN@69
722224µs617µsFoswiki::Prefs::::setSessionPreferencesFoswiki::Prefs::setSessionPreferences
11156µs1.00msFoswiki::Prefs::::newFoswiki::Prefs::new
11139µs17.7msFoswiki::Prefs::::loadSitePreferencesFoswiki::Prefs::loadSitePreferences
11118µs175msFoswiki::Prefs::::loadDefaultPreferencesFoswiki::Prefs::loadDefaultPreferences
11115µs29µsFoswiki::::BEGIN@2 Foswiki::BEGIN@2
11112µs145µsFoswiki::Prefs::::setUserPreferencesFoswiki::Prefs::setUserPreferences
1119µs15µsFoswiki::::BEGIN@3 Foswiki::BEGIN@3
1119µs25µsFoswiki::Prefs::::BEGIN@68Foswiki::Prefs::BEGIN@68
1114µs4µsFoswiki::Prefs::::BEGIN@72Foswiki::Prefs::BEGIN@72
0000s0sFoswiki::Prefs::::stringifyFoswiki::Prefs::stringify
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# See bottom of file for license and copyright information
2227µs244µs
# spent 29µs (15+15) within Foswiki::BEGIN@2 which was called: # once (15µs+15µs) by Foswiki::BEGIN@633 at line 2
use strict;
# spent 29µs making 1 call to Foswiki::BEGIN@2 # spent 15µs making 1 call to strict::import
3259µs221µs
# spent 15µs (9+6) within Foswiki::BEGIN@3 which was called: # once (9µs+6µs) by Foswiki::BEGIN@633 at line 3
use warnings;
# spent 15µs making 1 call to Foswiki::BEGIN@3 # spent 6µs making 1 call to warnings::import
4
5=begin TML
6
7---+ package Foswiki::Prefs
8
9Preferences are set in topics, using either 'Set' lines embedded in the
10topic text, or via PREFERENCE meta-data attached to the topic. A preference
11value has four _scopes_:
12 * _Global_ scope
13 * _Local_ scope
14 * _Web_ scope
15 * _Topic_ scope
16
17In _global_ scope, the value of a preference is determined by examining
18settings of the variable at different levels; default preferences, site level,
19parent web level, web level, user level, and topic level. To determine a
20preference value in global scope, you have to know what topic the topic is
21referenced in, to provide the scope for the request.
22
23A preference may be optionally defined in _Local_ scope, in which case the
24topic definition of the variable is always taken when it is referenced in the
25topic where it is defined. This is a special case to deal with the case where a
26preference has to have a different value in the defining topic.
27
28Values in global and local scope are accessed using =getPreference=/
29
30_Web_ scope is used by web access controls. Subwebs inherint access controls
31from parent webs and only from parent webs. Global and Local scopes are
32disconsidered.
33
34The final scope is _topic_ scope. In this scope, the value of the preference is
35taken directly from the contents of the topic, and is not overridden by wider
36scopes. Topic scope is used for topic access controls.
37
38Because the highest cost in evaluating preferences is reading the individual
39topics, preferences read from a topic are cached.
40
41An object of type Foswiki::Prefs is a singleton that provides an interface to
42this cache. Normally the cache is repopulated for each request, though it would
43be feasible to cache it on disc if some invalidation mechanism were available
44to deal with topic changes.
45
46This mechanism is composed by a front-end (implemented by this class) that
47deals with preferences logic and back-end objects that provide access to
48preferences values. There is one back-end for each topic (Web preferences are
49back-ends correspondind to the WebPreferences topic). Additionaly, there is a
50back-end object for session preferences. Each context has its own session
51preferences and thus its own session back-end object.
52
53Preferences are like a stack: there are many levels and higher levels have
54precedence over lower levels. It's also needed to push a context and pop to the
55earlier state. It would be easy to implement this stack, but then we would have
56a problem: to get the value of a preference we would need to scan each level
57and it's slow, so we need some fast mechanism to know in which level a
58preference is defined. Or we could copy the values from lower leves to higher
59ones and override the preferences defined at that level. This later approach
60wastes memory. This implementation picks the former and we use bitstrings and
61some maths to accomplish that. It's also flexible and it doesn't matter how
62preferences are stored.
63
64=cut
65
66package Foswiki::Prefs;
67
68224µs242µs
# spent 25µs (9+16) within Foswiki::Prefs::BEGIN@68 which was called: # once (9µs+16µs) by Foswiki::BEGIN@633 at line 68
use Assert;
# spent 25µs making 1 call to Foswiki::Prefs::BEGIN@68 # spent 16µs making 1 call to Assert::import
692100µs1805µs
# spent 805µs (312+494) within Foswiki::Prefs::BEGIN@69 which was called: # once (312µs+494µs) by Foswiki::BEGIN@633 at line 69
use Foswiki::Prefs::HASH ();
# spent 805µs making 1 call to Foswiki::Prefs::BEGIN@69
702104µs11.32ms
# spent 1.32ms (1.06+254µs) within Foswiki::Prefs::BEGIN@70 which was called: # once (1.06ms+254µs) by Foswiki::BEGIN@633 at line 70
use Foswiki::Prefs::Stack ();
# spent 1.32ms making 1 call to Foswiki::Prefs::BEGIN@70
71297µs1412µs
# spent 412µs (370+42) within Foswiki::Prefs::BEGIN@71 which was called: # once (370µs+42µs) by Foswiki::BEGIN@633 at line 71
use Foswiki::Prefs::Web ();
# spent 412µs making 1 call to Foswiki::Prefs::BEGIN@71
7221.59ms14µs
# spent 4µs within Foswiki::Prefs::BEGIN@72 which was called: # once (4µs+0s) by Foswiki::BEGIN@633 at line 72
use Scalar::Util ();
# spent 4µs making 1 call to Foswiki::Prefs::BEGIN@72
73
74=begin TML
75
76---++ ClassMethod new( $session )
77
78Creates a new Prefs object.
79
80=cut
81
82
# spent 1.00ms (56µs+948µs) within Foswiki::Prefs::new which was called: # once (56µs+948µs) by Foswiki::new at line 1752 of /var/www/foswiki11/lib/Foswiki.pm
sub new {
8311µs my ( $proto, $session ) = @_;
841700ns my $class = ref($proto) || $proto;
8517µs110µs my $this = {
# spent 10µs making 1 call to Foswiki::Prefs::Stack::new
86 'main' => Foswiki::Prefs::Stack->new(), # Main preferences stack
87 'paths' => {}, # Map paths to backend objects
88 'contexts' => [], # Store the main levels corresponding to contexts
89 'prefix' => [], # Map level => prefix uesed
90 # (plugins prefix prefs with PLUGINNAME_)
91 'webprefs' => {}, # Foswiki::Prefs::Web objs, used to get web prefs
92 'internals' => {}, # Store internal preferences
93 'session' => $session,
94 };
95
96133µs eval "use $Foswiki::cfg{Store}{PrefsBackend} ()";
# spent 76µs executing statements in string eval
# includes 407µs spent executing 1 call to 1 sub defined therein.
971400ns die $@ if $@;
98
99110µs return bless $this, $class;
100}
101
102=begin TML
103
104---++ ObjectMethod finish()
105Break circular references.
106
107=cut
108
109# Note to developers; please undef *all* fields in the object explicitly,
110# whether they are references or not. That way this method is "golden
111# documentation" of the live fields in the object.
112
# spent 4.10ms (1.58+2.52) within Foswiki::Prefs::finish which was called: # once (1.58ms+2.52ms) by Foswiki::finish at line 2163 of /var/www/foswiki11/lib/Foswiki.pm
sub finish {
1131800ns my $this = shift;
114
115179µs1316µs $this->{main}->finish() if $this->{main};
# spent 316µs making 1 call to Foswiki::Prefs::Stack::finish
11613µs undef $this->{main};
11713µs undef $this->{prefix};
1181600ns undef $this->{session};
11912µs undef $this->{contexts};
1201165µs if ( $this->{paths} ) {
121 foreach my $back ( values %{ $this->{paths} } ) {
122103808µs103689µs $back->finish();
# spent 689µs making 103 calls to Foswiki::Prefs::TopicRAM::finish, avg 7µs/call
123 }
124 }
125132µs undef $this->{paths};
1261133µs if ( $this->{webprefs} ) {
127 foreach my $webStack ( values %{ $this->{webprefs} } ) {
12892134µs921.51ms $webStack->finish();
# spent 1.51ms making 92 calls to Foswiki::Prefs::Web::finish, avg 16µs/call
129 }
130 }
131135µs undef $this->{webprefs};
13216µs undef $this->{internals};
133}
134
135# Get a backend object corresponding to the given $web,$topic
136# or Foswiki::Meta object
137
# spent 9.69s (3.07ms+9.69) within Foswiki::Prefs::_getBackend which was called 123 times, avg 78.8ms/call: # 92 times (2.37ms+8.20s) by Foswiki::Prefs::_pushWebInStack at line 163, avg 89.1ms/call # 14 times (196µs+3.18ms) by Foswiki::Prefs::pushTopicContext at line 278, avg 241µs/call # 7 times (352µs+1.30s) by Foswiki::Prefs::setPluginPreferences at line 329, avg 185ms/call # 7 times (87µs+1.06ms) by Foswiki::Prefs::pushTopicContext at line 281, avg 164µs/call # once (27µs+175ms) by Foswiki::Prefs::loadDefaultPreferences at line 361 # once (33µs+17.4ms) by Foswiki::Prefs::loadSitePreferences at line 379 # once (14µs+106µs) by Foswiki::Prefs::setUserPreferences at line 347
sub _getBackend {
13812351µs my $this = shift;
13912352µs my $metaObject = shift;
140123601µs1233.18ms $metaObject = Foswiki::Meta->new( $this->{session}, $metaObject, @_ )
# spent 3.18ms making 123 calls to Foswiki::Meta::new, avg 26µs/call
141 unless ref($metaObject) && UNIVERSAL::isa( $metaObject, 'Foswiki::Meta' );
142123266µs123482µs my $path = $metaObject->getPath();
# spent 482µs making 123 calls to Foswiki::Meta::getPath, avg 4µs/call
1431231.07ms1039.69s unless ( exists $this->{paths}{$path} ) {
# spent 9.69s making 103 calls to Foswiki::Prefs::TopicRAM::new, avg 94.0ms/call
144 $this->{paths}{$path} =
145 $Foswiki::cfg{Store}{PrefsBackend}->new($metaObject);
146 }
147123704µs return $this->{paths}{$path};
148}
149
150# Given a (sub)web and a stack object, push the (sub)web on the stack,
151# considering that part of the (sub)web may already be in the stack. This is
152# used to build, for example, Web/Subweb/WebA stack based on Web/Subweb or Web
153# stack.
154
# spent 8.21s (2.20ms+8.21) within Foswiki::Prefs::_pushWebInStack which was called 91 times, avg 90.2ms/call: # 91 times (2.20ms+8.21s) by Foswiki::Prefs::_getWebPrefsObj at line 199, avg 90.2ms/call
sub _pushWebInStack {
1559197µs my ( $this, $stack, $web ) = @_;
15691262µs my @webPath = split( /[\/\.]+/, $web );
1579131µs my $subWeb = '';
15891310µs91220µs $subWeb = join '/', splice @webPath, 0, $stack->size();
# spent 220µs making 91 calls to Foswiki::Prefs::Stack::size, avg 2µs/call
1599117µs my $back;
16091468µs foreach (@webPath) {
1619234µs $subWeb .= '/' if $subWeb;
1629240µs $subWeb .= $_;
16392250µs928.20s $back = $this->_getBackend( $subWeb, $Foswiki::cfg{WebPrefsTopicName} );
# spent 8.20s making 92 calls to Foswiki::Prefs::_getBackend, avg 89.1ms/call
16492389µs928.91ms $stack->newLevel($back);
# spent 8.91ms making 92 calls to Foswiki::Prefs::Stack::newLevel, avg 97µs/call
165 }
166}
167
168# Returns a Foswiki::Prefs::Web object. It consider the already existing
169# objects and build a new one only if it doesn't exist. And even if it doesn't
170# exist, consider existing ones to speedup the construction. Example:
171# Web/SubWeb already exists and we want Web/Subweb/WebA. Then we just push
172# WebA. If, instead, Web/Subweb/WebB exists, then we clone tha stack up to
173# Web/Subweb and push WebA on it.
174
# spent 8.22s (5.24ms+8.22) within Foswiki::Prefs::_getWebPrefsObj which was called 446 times, avg 18.4ms/call: # 446 times (5.24ms+8.22s) by Foswiki::Prefs::loadPreferences at line 232, avg 18.4ms/call
sub _getWebPrefsObj {
175446250µs my ( $this, $web ) = @_;
176446106µs my ( $stack, $level );
177
1784461.20ms if ( exists $this->{webprefs}{$web} ) {
179 return $this->{webprefs}{$web};
180 }
181
1829113µs my $part;
18391418µs91768µs $stack = Foswiki::Prefs::Stack->new();
# spent 768µs making 91 calls to Foswiki::Prefs::Stack::new, avg 8µs/call
18491391µs my @path = split /[\/\.]+/, $web;
1859183µs my @websToAdd = ( pop @path );
1869189µs while ( @path > 0 ) {
1875256µs $part = join( '/', @path );
1885250µs if ( exists $this->{webprefs}{$part} ) {
1895128µs my $base = $this->{webprefs}{$part};
19051338µs1024.64ms $stack =
# spent 4.12ms making 36 calls to Foswiki::Prefs::Web::cloneStack, avg 114µs/call # spent 478µs making 51 calls to Foswiki::Prefs::Web::isInTopOfStack, avg 9µs/call # spent 45µs making 15 calls to Foswiki::Prefs::Web::stack, avg 3µs/call
191 $base->isInTopOfStack()
192 ? $base->stack()
193 : $base->cloneStack( scalar(@path) - 1 );
1945151µs last;
195 }
19612µs unshift @websToAdd, pop @path;
197 }
198
19991217µs918.21s $this->_pushWebInStack( $stack, $web );
# spent 8.21s making 91 calls to Foswiki::Prefs::_pushWebInStack, avg 90.2ms/call
20091158µs $part = join( '/', @path );
2019158µs $level = scalar @path;
2029187µs foreach (@websToAdd) {
2039233µs $part .= '/' if $part;
2049239µs $part .= $_;
205921.08ms92797µs $this->{webprefs}{$part} = Foswiki::Prefs::Web->new( $stack, $level++ );
# spent 797µs making 92 calls to Foswiki::Prefs::Web::new, avg 9µs/call
206 }
20791471µs return $this->{webprefs}{$web};
208}
209
210=begin TML
211
212---++ ObjectMethod loadPreferences( $topicObject ) -> $back
213
214Invoked from Foswiki::Meta to load the preferences into the preferences
215cache. used as part of the lazy-loading of preferences.
216
217Web preferences are loaded from the {WebPrefsTopicName}.
218
219=cut
220
221
# spent 8.27s (9.28ms+8.26) within Foswiki::Prefs::loadPreferences which was called 679 times, avg 12.2ms/call: # 679 times (9.28ms+8.26s) by Foswiki::Meta::getPreference at line 592 of /var/www/foswiki11/lib/Foswiki/Meta.pm, avg 12.2ms/call
sub loadPreferences {
222679254µs my ( $this, $topicObject ) = @_;
223
224679967µs6791.58ms my $path = $topicObject->getPath();
# spent 1.58ms making 679 calls to Foswiki::Meta::getPath, avg 2µs/call
225
226 # $topicObject->session->logger->log( 'debug',
227 # "Loading preferences for $path\n" )
228 # if DEBUG;
229
230679112µs my $obj;
231
2326793.62ms22508.26s if ( $topicObject->topic() ) {
# spent 8.22s making 446 calls to Foswiki::Prefs::_getWebPrefsObj, avg 18.4ms/call # spent 34.8ms making 233 calls to Foswiki::Prefs::TopicRAM::new, avg 150µs/call # spent 1.53ms making 892 calls to Foswiki::Meta::web, avg 2µs/call # spent 1.25ms making 679 calls to Foswiki::Meta::topic, avg 2µs/call
233 $obj = $Foswiki::cfg{Store}{PrefsBackend}->new($topicObject);
234 }
235 elsif ( $topicObject->web() ) {
236 $obj = $this->_getWebPrefsObj( $topicObject->web() );
237 }
238 elsif ( $Foswiki::cfg{LocalSitePreferences} ) {
239 my ( $web, $topic ) =
240 $this->{session}
241 ->normalizeWebTopicName( undef, $Foswiki::cfg{LocalSitePreferences} );
242
243 # Use the site preferences
244 $obj = $this->_getBackend( $web, $topic );
245 }
246
2476791.53ms return $obj;
248}
249
250=begin TML
251
252---++ ObjectMethod pushTopicContext( $web, $topic )
253
254Reconfigures the preferences so that general preference values appear
255to come from $web.$topic. The topic context can be popped again using
256popTopicContext.
257
258=cut
259
260
# spent 7.33ms (624µs+6.71) within Foswiki::Prefs::pushTopicContext which was called 7 times, avg 1.05ms/call: # 6 times (497µs+2.30ms) by Foswiki::INCLUDE at line 201 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 467µs/call # once (128µs+4.41ms) by Foswiki::new at line 1967 of /var/www/foswiki11/lib/Foswiki.pm
sub pushTopicContext {
26177µs my ( $this, $web, $topic ) = @_;
262
26375µs my $stack = $this->{main};
26472µs my %internals;
265783µs while ( my ( $k, $v ) = each %{ $this->{internals} } ) {
266 $internals{$k} = $v;
267 }
268 push(
269739µs716µs @{ $this->{contexts} },
# spent 16µs making 7 calls to Foswiki::Prefs::Stack::size, avg 2µs/call
270 { internals => \%internals, level => $stack->size() - 1 }
271 );
272736µs my @webPath = split( /[\/\.]+/, $web );
27372µs my $subWeb = '';
27471µs my $back;
27578µs foreach (@webPath) {
276146µs $subWeb .= '/' if $subWeb;
277144µs $subWeb .= $_;
2781435µs143.38ms $back = $this->_getBackend( $subWeb, $Foswiki::cfg{WebPrefsTopicName} );
# spent 3.38ms making 14 calls to Foswiki::Prefs::_getBackend, avg 241µs/call
2791433µs141.09ms $stack->newLevel($back);
# spent 1.09ms making 14 calls to Foswiki::Prefs::Stack::newLevel, avg 78µs/call
280 }
281715µs71.15ms $back = $this->_getBackend( $web, $topic );
# spent 1.15ms making 7 calls to Foswiki::Prefs::_getBackend, avg 164µs/call
282712µs7106µs $stack->newLevel($back);
# spent 106µs making 7 calls to Foswiki::Prefs::Stack::newLevel, avg 15µs/call
283747µs14320µs $stack->newLevel( Foswiki::Prefs::HASH->new() );
# spent 188µs making 7 calls to Foswiki::Prefs::HASH::new, avg 27µs/call # spent 132µs making 7 calls to Foswiki::Prefs::Stack::newLevel, avg 19µs/call
284
2857165µs40660µs while ( my ( $k, $v ) = each %{ $this->{internals} } ) {
# spent 660µs making 40 calls to Foswiki::Prefs::Stack::insert, avg 17µs/call
286 $stack->insert( 'Set', $k, $v );
287 }
288
289}
290
291=begin TML
292
293---+++ popTopicContext()
294
295Returns the context to the state it was in before the
296=pushTopicContext= was last called.
297
298=cut
299
300
# spent 3.65ms (371µs+3.28) within Foswiki::Prefs::popTopicContext which was called 6 times, avg 609µs/call: # 6 times (371µs+3.28ms) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm:348] at line 346 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 609µs/call
sub popTopicContext {
30164µs my $this = shift;
30265µs my $stack = $this->{main};
303611µs my $context = pop( @{ $this->{contexts} } );
30464µs my $level = $context->{level};
305692µs while ( my ( $k, $v ) = each %{ $context->{internals} } ) {
306 $this->{internals}{$k} = $v;
307 }
308673µs63.20ms $stack->restore($level);
# spent 3.20ms making 6 calls to Foswiki::Prefs::Stack::restore, avg 534µs/call
30967µs splice @{ $this->{prefix} }, $level + 1 if @{ $this->{prefix} } > $level;
310
311 # Note: this used to get the web from (-3) - but that only gives the
312 # last component of the web path, and fails if the web name is empty.
313638µs1243µs my $toRef = $stack->backAtLevel(-2)->topicObject;
# spent 24µs making 6 calls to Foswiki::Prefs::TopicRAM::topicObject, avg 4µs/call # spent 19µs making 6 calls to Foswiki::Prefs::Stack::backAtLevel, avg 3µs/call
314688µs1235µs return ( $toRef->web(), $toRef->topic() );
# spent 20µs making 6 calls to Foswiki::Meta::web, avg 3µs/call # spent 15µs making 6 calls to Foswiki::Meta::topic, avg 2µs/call
315}
316
317=begin TML
318
319---++ ObjectMethod setPluginPreferences( $web, $plugin )
320
321Reads preferences from the given plugin topic and injects them into
322the plugin preferences cache. Preferences cannot be finalised in
323plugin topics.
324
325=cut
326
327
# spent 1.30s (367µs+1.30) within Foswiki::Prefs::setPluginPreferences which was called 7 times, avg 185ms/call: # 7 times (367µs+1.30s) by Foswiki::Plugin::registerSettings at line 216 of /var/www/foswiki11/lib/Foswiki/Plugin.pm, avg 185ms/call
sub setPluginPreferences {
328719µs my ( $this, $web, $plugin ) = @_;
329730µs71.30s my $back = $this->_getBackend( $web, $plugin );
# spent 1.30s making 7 calls to Foswiki::Prefs::_getBackend, avg 185ms/call
330739µs my $prefix = uc($plugin) . '_';
331716µs my $stack = $this->{main};
332764µs7689µs $stack->newLevel( $back, $prefix );
# spent 689µs making 7 calls to Foswiki::Prefs::Stack::newLevel, avg 98µs/call
3337124µs743µs $this->{prefix}->[ $stack->size() - 1 ] = $prefix;
# spent 43µs making 7 calls to Foswiki::Prefs::Stack::size, avg 6µs/call
334}
335
336=begin TML
337
338---++ ObjectMethod setUserPreferences( $wikiname )
339
340Reads preferences from the given user topic and pushes them to the preferences
341stack.
342
343=cut
344
345
# spent 145µs (12+134) within Foswiki::Prefs::setUserPreferences which was called: # once (12µs+134µs) by Foswiki::new at line 1963 of /var/www/foswiki11/lib/Foswiki.pm
sub setUserPreferences {
34611µs my ( $this, $wn ) = @_;
34712µs1120µs my $back = $this->_getBackend( $Foswiki::cfg{UsersWebName}, $wn );
# spent 120µs making 1 call to Foswiki::Prefs::_getBackend
34817µs114µs $this->{main}->newLevel($back);
# spent 14µs making 1 call to Foswiki::Prefs::Stack::newLevel
349}
350
351=begin TML
352
353---++ ObjectMethod loadDefaultPreferences()
354
355Add default preferences to this preferences stack.
356
357=cut
358
359
# spent 175ms (18µs+175) within Foswiki::Prefs::loadDefaultPreferences which was called: # once (18µs+175ms) by Foswiki::new at line 1934 of /var/www/foswiki11/lib/Foswiki.pm
sub loadDefaultPreferences {
3601500ns my $this = shift;
36114µs1175ms my $back = $this->_getBackend( $Foswiki::cfg{SystemWebName},
# spent 175ms making 1 call to Foswiki::Prefs::_getBackend
362 $Foswiki::cfg{SitePrefsTopicName} );
363111µs1314µs $this->{main}->newLevel($back);
# spent 314µs making 1 call to Foswiki::Prefs::Stack::newLevel
364}
365
366=begin TML
367
368---++ ObjectMethod loadSitePreferences()
369Add local site preferences to this preferences stack.
370
371=cut
372
373
# spent 17.7ms (39µs+17.7) within Foswiki::Prefs::loadSitePreferences which was called: # once (39µs+17.7ms) by Foswiki::new at line 1958 of /var/www/foswiki11/lib/Foswiki.pm
sub loadSitePreferences {
37411µs my $this = shift;
37518µs if ( $Foswiki::cfg{LocalSitePreferences} ) {
376115µs160µs my ( $web, $topic ) =
# spent 60µs making 1 call to Foswiki::normalizeWebTopicName
377 $this->{session}
378 ->normalizeWebTopicName( undef, $Foswiki::cfg{LocalSitePreferences} );
37914µs117.4ms my $back = $this->_getBackend( $web, $topic );
# spent 17.4ms making 1 call to Foswiki::Prefs::_getBackend
38013µs1181µs $this->{main}->newLevel($back);
# spent 181µs making 1 call to Foswiki::Prefs::Stack::newLevel
381 }
382}
383
384=begin TML
385
386---++ ObjectMethod setSessionPreferences( %values )
387
388Set the preference values in the parameters in the SESSION stack.
389
390=cut
391
392
# spent 617µs (224+393) within Foswiki::Prefs::setSessionPreferences which was called 7 times, avg 88µs/call: # 6 times (166µs+274µs) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm:331] at line 224 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 73µs/call # once (58µs+118µs) by Foswiki::UI::View::view at line 343 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
sub setSessionPreferences {
393727µs my ( $this, %values ) = @_;
39477µs my $stack = $this->{main};
39572µs my $num = 0;
396748µs while ( my ( $k, $v ) = each %values ) {
397831µs852µs next if $stack->finalized($k);
# spent 52µs making 8 calls to Foswiki::Prefs::Stack::finalized, avg 7µs/call
398836µs8340µs $num += $stack->insert( 'Set', $k, $v );
# spent 340µs making 8 calls to Foswiki::Prefs::Stack::insert, avg 43µs/call
399 }
400
401743µs return $num;
402}
403
404=begin TML
405
406---++ ObjectMethod setInternalPreferences( %values )
407
408Designed specifically for imposing the value of preferences on a short-term
409basis in the code, internal preferences override all other definitions of
410the same tag. This function should be used with great care.
411
412For those who are used to the old code, internal preferences replace the old
413SESSION_TAGS field from the Foswiki object.
414
415=cut
416
417
# spent 1.11ms within Foswiki::Prefs::setInternalPreferences which was called 125 times, avg 9µs/call: # 49 times (401µs+0s) by Foswiki::innerExpandMacros at line 2810 of /var/www/foswiki11/lib/Foswiki.pm, avg 8µs/call # 49 times (397µs+0s) by Foswiki::innerExpandMacros at line 2837 of /var/www/foswiki11/lib/Foswiki.pm, avg 8µs/call # 7 times (78µs+0s) by Foswiki::expandMacros at line 3337 of /var/www/foswiki11/lib/Foswiki.pm, avg 11µs/call # 7 times (52µs+0s) by Foswiki::expandMacros at line 3354 of /var/www/foswiki11/lib/Foswiki.pm, avg 7µs/call # 6 times (106µs+0s) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm:331] at line 227 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 18µs/call # 6 times (52µs+0s) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm:348] at line 337 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 9µs/call # once (18µs+0s) by Foswiki::new at line 1947 of /var/www/foswiki11/lib/Foswiki.pm
sub setInternalPreferences {
418125292µs my ( $this, %values ) = @_;
419
4201251.01ms while ( my ( $k, $v ) = each %values ) {
421 $this->{internals}{$k} = $v;
422 }
423}
424
425=begin TML
426
427---++ ObjectMethod getPreference( $key ) -> $value
428 * =$key - key to look up
429
430Returns the finalised preference value.
431
432=cut
433
434
# spent 17.7ms (10.5+7.18) within Foswiki::Prefs::getPreference which was called 717 times, avg 25µs/call: # 454 times (6.80ms+4.47ms) by Foswiki::_expandMacroOnTopicRendering at line 3128 of /var/www/foswiki11/lib/Foswiki.pm, avg 25µs/call # 50 times (937µs+655µs) by Foswiki::Func::getPreferencesValue at line 768 of /var/www/foswiki11/lib/Foswiki/Func.pm, avg 32µs/call # 49 times (274µs+102µs) by Foswiki::innerExpandMacros at line 2803 of /var/www/foswiki11/lib/Foswiki.pm, avg 8µs/call # 49 times (220µs+77µs) by Foswiki::innerExpandMacros at line 2804 of /var/www/foswiki11/lib/Foswiki.pm, avg 6µs/call # 45 times (1.23ms+1.07ms) by Foswiki::getSkin at line 1386 of /var/www/foswiki11/lib/Foswiki.pm, avg 51µs/call # 12 times (171µs+118µs) by Foswiki::If::OP_defined::evaluate at line 35 of /var/www/foswiki11/lib/Foswiki/If/OP_defined.pm, avg 24µs/call # 7 times (21µs+0s) by Foswiki::expandMacros at line 3335 of /var/www/foswiki11/lib/Foswiki.pm, avg 3µs/call # 7 times (16µs+0s) by Foswiki::expandMacros at line 3336 of /var/www/foswiki11/lib/Foswiki.pm, avg 2µs/call # 6 times (242µs+222µs) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm:331] at line 291 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 77µs/call # 6 times (39µs+0s) by Foswiki::INCLUDE at line 214 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 6µs/call # 6 times (17µs+0s) by Foswiki::INCLUDE at line 215 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 3µs/call # 5 times (136µs+131µs) by Foswiki::Render::getRenderedVersion at line 1428 of /var/www/foswiki11/lib/Foswiki/Render.pm, avg 53µs/call # 5 times (110µs+104µs) by Foswiki::INCLUDE at line 130 of /var/www/foswiki11/lib/Foswiki/Macros/INCLUDE.pm, avg 43µs/call # 5 times (81µs+47µs) by Foswiki::WIKINAME at line 12 of /var/www/foswiki11/lib/Foswiki/Macros/WIKINAME.pm, avg 26µs/call # 3 times (63µs+49µs) by Foswiki::Func::getPluginPreferencesValue at line 792 of /var/www/foswiki11/lib/Foswiki/Func.pm, avg 38µs/call # 2 times (36µs+21µs) by Foswiki::WIKIUSERNAME at line 12 of /var/www/foswiki11/lib/Foswiki/Macros/WIKIUSERNAME.pm, avg 28µs/call # 2 times (32µs+18µs) by Foswiki::USERNAME at line 13 of /var/www/foswiki11/lib/Foswiki/Macros/USERNAME.pm, avg 25µs/call # once (38µs+38µs) by Foswiki::_lookupIcon at line 26 of /var/www/foswiki11/lib/Foswiki/Macros/ICON.pm # once (37µs+19µs) by Foswiki::Plugins::enable at line 249 of /var/www/foswiki11/lib/Foswiki/Plugins.pm # once (27µs+23µs) by Foswiki::UI::View::view at line 228 of /var/www/foswiki11/lib/Foswiki/UI/View.pm # once (20µs+20µs) by Foswiki::Render::_linkToolTipInfo at line 477 of /var/www/foswiki11/lib/Foswiki/Render.pm
sub getPreference {
435717437µs my ( $this, $key ) = @_;
4367171.03ms if ( defined $this->{internals}{$key} ) {
437 return $this->{internals}{$key};
438 }
439
44057087µs my $value;
441570250µs my $stack = $this->{main};
442570977µs5701.19ms my $prevLev = $stack->backAtLevel(-2);
# spent 1.19ms making 570 calls to Foswiki::Prefs::Stack::backAtLevel, avg 2µs/call
4435702.11ms10463.42ms if ( $prevLev && !$stack->finalizedBefore( $key, -2 ) ) {
# spent 2.20ms making 570 calls to Foswiki::Prefs::Stack::finalizedBefore, avg 4µs/call # spent 1.21ms making 476 calls to Foswiki::Prefs::TopicRAM::getLocal, avg 3µs/call
444 $value = $prevLev->getLocal($key);
445 }
4465701.10ms5701.22ms if ( !defined $value && $stack->prefIsDefined($key) ) {
# spent 1.22ms making 570 calls to Foswiki::Prefs::Stack::prefIsDefined, avg 2µs/call
44783160µs83944µs my $defLevel = $stack->getDefinitionLevel($key);
# spent 944µs making 83 calls to Foswiki::Prefs::Stack::getDefinitionLevel, avg 11µs/call
4488361µs my $prefix = $this->{prefix}->[$defLevel];
4498372µs $key =~ s/^\Q$prefix\E// if $prefix;
45083298µs166406µs $value = $stack->backAtLevel($defLevel)->get($key);
# spent 244µs making 81 calls to Foswiki::Prefs::TopicRAM::get, avg 3µs/call # spent 154µs making 83 calls to Foswiki::Prefs::Stack::backAtLevel, avg 2µs/call # spent 8µs making 2 calls to Foswiki::Prefs::HASH::get, avg 4µs/call
451 }
4525701.60ms return $value;
453}
454
455=begin TML
456
457---++ ObjectMethod stringify([$key]) -> $text
458
459Generate TML-formatted information about the key (all keys if $key is undef)
460
461=cut
462
463sub stringify {
464 my ( $this, $key ) = @_;
465
466 my $stack = $this->{main};
467 my @keys = defined $key ? ($key) : sort $stack->prefs;
468 my @list;
469 foreach my $k (@keys) {
470 my $val = Foswiki::entityEncode( $this->getPreference($k) || '' );
471 push( @list, ' * Set ' . "$k = \"$val\"" );
472 next unless exists $stack->{'map'}{$k};
473 my $defLevel = $stack->getDefinitionLevel($k);
474 if ( $stack->backAtLevel($defLevel)->can('topicObject') ) {
475 my $topicObject = $stack->backAtLevel($defLevel)->topicObject();
476 push( @list,
477 " * $k was "
478 . ( $stack->finalized($k) ? '*finalised*' : 'defined' )
479 . ' in <nop>'
480 . $topicObject->web() . '.'
481 . $topicObject->topic() );
482 }
483 }
484
485 @keys =
486 defined $key ? ($key) : ( sort $stack->backAtLevel(-2)->localPrefs );
487 foreach my $k (@keys) {
488 next
489 unless defined $stack->backAtLevel(-2)->getLocal($k)
490 && !$stack->finalizedBefore( $k, -2 );
491 my $val =
492 Foswiki::entityEncode( $stack->backAtLevel(-2)->getLocal($k) );
493 push( @list, ' * Local ' . "$k = \"$val\"" );
494 }
495
496 return join( "\n", @list ) . "\n";
497}
498
49912µs1;
500__END__