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

Filename/var/www/foswiki11/lib/Foswiki/MetaCache.pm
StatementsExecuted 241464 statements in 245ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2636643241ms1.16sFoswiki::MetaCache::::getFoswiki::MetaCache::get
1112.79ms2.79msFoswiki::MetaCache::::finishFoswiki::MetaCache::finish
11133µs33µsFoswiki::MetaCache::::newFoswiki::MetaCache::new
11114µs27µsFoswiki::MetaCache::::BEGIN@3Foswiki::MetaCache::BEGIN@3
11110µs40µsFoswiki::MetaCache::::BEGIN@23Foswiki::MetaCache::BEGIN@23
11110µs52µsFoswiki::MetaCache::::BEGIN@31Foswiki::MetaCache::BEGIN@31
11110µs22µsFoswiki::MetaCache::::BEGIN@20Foswiki::MetaCache::BEGIN@20
1119µs14µsFoswiki::MetaCache::::BEGIN@4Foswiki::MetaCache::BEGIN@4
1114µs4µsFoswiki::MetaCache::::BEGIN@24Foswiki::MetaCache::BEGIN@24
1113µs3µsFoswiki::MetaCache::::BEGIN@26Foswiki::MetaCache::BEGIN@26
1113µs3µsFoswiki::MetaCache::::BEGIN@21Foswiki::MetaCache::BEGIN@21
1113µs3µsFoswiki::MetaCache::::BEGIN@22Foswiki::MetaCache::BEGIN@22
1113µs3µsFoswiki::MetaCache::::BEGIN@25Foswiki::MetaCache::BEGIN@25
0000s0sFoswiki::MetaCache::::hasCachedFoswiki::MetaCache::hasCached
0000s0sFoswiki::MetaCache::::removeMetaFoswiki::MetaCache::removeMeta
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
2package Foswiki::MetaCache;
3231µs240µs
# spent 27µs (14+13) within Foswiki::MetaCache::BEGIN@3 which was called: # once (14µs+13µs) by Foswiki::Search::BEGIN@24 at line 3
use strict;
# spent 27µs making 1 call to Foswiki::MetaCache::BEGIN@3 # spent 13µs making 1 call to strict::import
4237µs220µs
# spent 14µs (9+5) within Foswiki::MetaCache::BEGIN@4 which was called: # once (9µs+5µs) by Foswiki::Search::BEGIN@24 at line 4
use warnings;
# spent 14µs making 1 call to Foswiki::MetaCache::BEGIN@4 # spent 5µs making 1 call to warnings::import
5
6=begin TML
7
8---+ package Foswiki::MetaCache
9
10A cache of Meta objects - initially used to speed up searching and sorting, but by foswiki 2.0 hopefully this
11will be used for all readonly accesses to the store.
12
13Replaces the mishmash of the Search InfoCache Support package; cache of topic info.
14When information about search hits is
15compiled for output, this cache is used to avoid recovering the same info
16about the same topic more than once.
17
18=cut
19
20222µs234µs
# spent 22µs (10+12) within Foswiki::MetaCache::BEGIN@20 which was called: # once (10µs+12µs) by Foswiki::Search::BEGIN@24 at line 20
use Assert;
# spent 22µs making 1 call to Foswiki::MetaCache::BEGIN@20 # spent 12µs making 1 call to Assert::import
21218µs13µs
# spent 3µs within Foswiki::MetaCache::BEGIN@21 which was called: # once (3µs+0s) by Foswiki::Search::BEGIN@24 at line 21
use Foswiki::Func ();
# spent 3µs making 1 call to Foswiki::MetaCache::BEGIN@21
22220µs13µs
# spent 3µs within Foswiki::MetaCache::BEGIN@22 which was called: # once (3µs+0s) by Foswiki::Search::BEGIN@24 at line 22
use Foswiki::Meta ();
# spent 3µs making 1 call to Foswiki::MetaCache::BEGIN@22
23227µs270µs
# spent 40µs (10+30) within Foswiki::MetaCache::BEGIN@23 which was called: # once (10µs+30µs) by Foswiki::Search::BEGIN@24 at line 23
use Scalar::Util qw(blessed);
# spent 40µs making 1 call to Foswiki::MetaCache::BEGIN@23 # spent 30µs making 1 call to Exporter::import
24217µs14µs
# spent 4µs within Foswiki::MetaCache::BEGIN@24 which was called: # once (4µs+0s) by Foswiki::Search::BEGIN@24 at line 24
use Foswiki::Func ();
# spent 4µs making 1 call to Foswiki::MetaCache::BEGIN@24
25222µs13µs
# spent 3µs within Foswiki::MetaCache::BEGIN@25 which was called: # once (3µs+0s) by Foswiki::Search::BEGIN@24 at line 25
use Foswiki::Meta ();
# spent 3µs making 1 call to Foswiki::MetaCache::BEGIN@25
26224µs13µs
# spent 3µs within Foswiki::MetaCache::BEGIN@26 which was called: # once (3µs+0s) by Foswiki::Search::BEGIN@24 at line 26
use Foswiki::Users::BaseUserMapping ();
# spent 3µs making 1 call to Foswiki::MetaCache::BEGIN@26
27
28#use Monitor ();
29#Monitor::MonitorMethod('Foswiki::MetaCache', 'getTopicListIterator');
30
312647µs294µs
# spent 52µs (10+42) within Foswiki::MetaCache::BEGIN@31 which was called: # once (10µs+42µs) by Foswiki::Search::BEGIN@24 at line 31
use constant TRACE => 0;
# spent 52µs making 1 call to Foswiki::MetaCache::BEGIN@31 # spent 42µs making 1 call to constant::import
32
33=begin TML
34
35---++ ClassMethod new($session)
36
37=cut
38
39
# spent 33µs within Foswiki::MetaCache::new which was called: # once (33µs+0s) by Foswiki::Search::metacache at line 93 of /var/www/foswiki11/lib/Foswiki/Search.pm
sub new {
4012µs my ( $class, $session ) = @_;
41
42 #my $this = $class->SUPER::new([]);
43127µs my $this = bless(
44 {
45 session => $session,
46 cache => {},
47 new_count => 0,
48 get_count => 0,
49 undef_count => 0,
50 meta_cache_session_user => $session->{user},
51 },
52 $class
53 );
54
5517µs return $this;
56}
57
58=begin TML
59
60---++ ObjectMethod finish()
61Break circular references.
62
63 Note to developers; please undef *all* fields in the object explicitly,
64 whether they are references or not. That way this method is "golden
65 documentation" of the live fields in the object.
66
67=cut
68
69
# spent 2.79ms within Foswiki::MetaCache::finish which was called: # once (2.79ms+0s) by Foswiki::Search::finish at line 77 of /var/www/foswiki11/lib/Foswiki/Search.pm
sub finish {
701800ns my $this = shift;
7111µs undef $this->{session};
72
73 #must clear cache every request until the cache is hooked up to Store's save
74
7515µs foreach my $web ( keys( %{ $this->{cache} } ) ) {
762709µs foreach my $topic ( keys( %{ $this->{cache}->{$web} } ) ) {
773051.89ms undef $this->{cache}->{$web}{$topic};
78305106µs $this->{undef_count}++;
79 }
80267µs undef $this->{cache}->{$web};
81 }
8211µs undef $this->{cache};
83
8416µs if (TRACE) {
85 print STDERR
86"MetaCache: new: $this->{new_count} get: $this->{get_count} undef: $this->{undef_count} \n";
87 }
88
89}
90
91=begin TML
92
93---++ ObjectMethod hasCached($webtopic) -> boolean
94
95returns true if the topic is already int he cache.
96
97=cut
98
99sub hasCached {
100 my ( $this, $web, $topic ) = @_;
101 ASSERT( defined($topic) ) if DEBUG;
102 return unless ( defined($topic) );
103
104 return defined( $this->{cache}->{$web}{$topic} );
105}
106
107sub removeMeta {
108 my ( $this, $web, $topic ) = @_;
109
110 if ( defined($topic) ) {
111 my $cached_webtopic = $this->{cache}->{$web}{$topic};
112
113 if ($cached_webtopic) {
114 $cached_webtopic->finish() if blessed($cached_webtopic);
115 delete $this->{cache}->{$web}{$topic};
116 }
117 }
118 elsif ( defined($web) ) {
119 foreach my $topic ( keys( %{ $this->{cache}->{$web} } ) ) {
120 $this->removeMeta( $web, $topic );
121 }
122 delete $this->{cache}->{$web};
123 }
124
125 return;
126}
127
128=begin TML
129
130---++ ObjectMethod get($webtopic, $meta) -> a cache obj (sorry, needs to be refactored out to return a Foswiki::Meta obj only
131
132get a requested meta object - web or topic typically, might work for attachments too
133
134optionally the $meta parameter can be used to add that to the cache - useful if you've already loaded and parsed the topic.
135
136=cut
137
138
# spent 1.16s (241ms+918ms) within Foswiki::MetaCache::get which was called 26366 times, avg 44µs/call: # 8845 times (58.0ms+99.0ms) by Foswiki::Search::formatResults at line 787 of /var/www/foswiki11/lib/Foswiki/Search.pm, avg 18µs/call # 8760 times (87.1ms+803ms) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 230 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm, avg 102µs/call # 8760 times (95.6ms+14.5ms) by Foswiki::Search::InfoCache::addTopic at line 99 of /var/www/foswiki11/lib/Foswiki/Search/InfoCache.pm, avg 13µs/call # once (74µs+657µs) by Foswiki::Store::QueryAlgorithms::BruteForce::_webQuery at line 114 of /var/www/foswiki11/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm
sub get {
1392636617.0ms my ( $this, $web, $topic, $meta ) = @_;
1402636612.7ms87607.56ms ASSERT( $meta->isa('Foswiki::Meta') ) if ( defined($meta) and DEBUG );
# spent 7.56ms making 8760 calls to Assert::ASSERTS_OFF, avg 863ns/call
141
142263663.92ms if ( !defined($topic) ) {
143
144#there are some instances - like the result set sorting, where we need to quickly pass "$web.$topic"
145 ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( '', $web );
146 }
147
148#print STDERR "------------do i get a lookin ($web, $topic) as ".$this->{session}->{user}."ne ".$this->{meta_cache_session_user}."\n";
149263668.19ms $this->{get_count}++;
150
1512636613.6ms unless ( $this->{cache}->{$web} ) {
152 $this->{cache}->{$web} = {};
153 }
154
155#if we've _returned_ to the real session user, after promotion, undef cached topic's loaded during promotion
156#see Item10097 WARNING: this is a pretty dangerous 'fix' as any developer that writes a replacement metacache for their store/search needs to make sure they too grok that the session user is promoted to admin several times per request :(
1572636635.2ms if (
158
159#($this->{non_session_user_entries}) and #BUGGER. turns out we start with the same local user=admin rubbish to get the WebPrefs
160 ( defined( $this->{cache}->{$web}{$topic} ) )
161 and ( defined( $this->{cache}->{$web}{$topic}->{allowViewUser} ) )
162 )
163 {
164 undef $this->{cache}->{$web}{$topic};
165 delete $this->{cache}->{$web}{$topic};
166 $this->{undef_count}++;
167
168 #print STDERR "---- discard $web . $topic\n";
169
170 }
1712636611.6ms unless ( $this->{cache}->{$web}{$topic} ) {
172
173 #print STDERR "---- create new $web . $topic\n";
174
175305502µs $this->{cache}->{$web}{$topic} = {};
176305119µs if ( defined($meta) ) {
177 $this->{cache}->{$web}{$topic}->{tom} = $meta;
178 }
179 else {
1803051.45ms305778ms $this->{cache}->{$web}{$topic}->{tom} =
# spent 778ms making 305 calls to Foswiki::Meta::load, avg 2.55ms/call
181 Foswiki::Meta->load( $this->{session}, $web, $topic );
182 }
183 return
184305582µs if ( !defined( $this->{cache}->{$web}{$topic}->{tom} )
185 or $this->{cache}->{$web}{$topic}->{tom} eq '' );
186
187305103µs $this->{new_count}++;
188
189 #TODO: extract this to the Meta Class, or remove entirely
190 # Extract sort fields
191305527µs3054.46ms my $ri = $this->{cache}->{$web}{$topic}->{tom}->getRevisionInfo();
# spent 4.46ms making 305 calls to Foswiki::Meta::getRevisionInfo, avg 15µs/call
192
193 # Rename fields to match sorting criteria
194305375µs $this->{cache}->{$web}{$topic}->{editby} = $ri->{author} || '';
195305317µs $this->{cache}->{$web}{$topic}->{modified} = $ri->{date};
196305278µs $this->{cache}->{$web}{$topic}->{revNum} = $ri->{version};
197
198305919µs305106ms $this->{cache}->{$web}{$topic}->{allowView} =
# spent 107ms making 305 calls to Foswiki::Meta::haveAccess, avg 351µs/call, recursion: max depth 1, sum of overlapping time 1.58ms
199 $this->{cache}->{$web}{$topic}->{tom}->haveAccess('VIEW');
200305580µs if ( $this->{session}->{user} ne $this->{meta_cache_session_user} ) {
2018630µs $this->{non_session_user_entries} = 1;
20286118µs $this->{cache}->{$web}{$topic}->{allowViewUser} =
203 $this->{session}->{user};
204
205#print STDERR "---- switched from ".$this->{meta_cache_session_user}." to ".$this->{session}->{user}." for $web . $topic\n";
206 }
207
208 }
209
2102636624.9ms2636620.8ms ASSERT( $this->{cache}->{$web}{$topic}->{tom}->isa('Foswiki::Meta') )
# spent 20.8ms making 26366 calls to Assert::ASSERTS_OFF, avg 791ns/call
211 if DEBUG;
212
21326366108ms return $this->{cache}->{$web}{$topic};
214}
215
21612µs1;
217__END__