← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:14 2015

Filename/var/www/foswikidev/core/lib/Foswiki/Store.pm
StatementsExecuted 877497 statements in 2.17s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
13201152843ms3.45sFoswiki::Store::::encodeFoswiki::Store::encode
12679143784ms3.78sFoswiki::Store::::decodeFoswiki::Store::decode
5035043191ms191msFoswiki::Store::::cleanUpRevIDFoswiki::Store::cleanUpRevID
1112.87ms3.23msFoswiki::Store::::BEGIN@63Foswiki::Store::BEGIN@63
5911336µs365µsFoswiki::Store::::getAttachmentURLFoswiki::Store::getAttachmentURL
11116µs50µsFoswiki::Store::::getWorkAreaFoswiki::Store::getWorkArea
11112µs25µsFoswiki::Store::::BEGIN@55Foswiki::Store::BEGIN@55
11112µs12µsFoswiki::Store::::newFoswiki::Store::new
1119µs32µsFoswiki::Store::::BEGIN@59Foswiki::Store::BEGIN@59
1118µs12µsFoswiki::Store::::BEGIN@56Foswiki::Store::BEGIN@56
1118µs105µsFoswiki::Store::::BEGIN@58Foswiki::Store::BEGIN@58
1115µs5µsFoswiki::Store::::BEGIN@65Foswiki::Store::BEGIN@65
1113µs3µsFoswiki::Store::::BEGIN@61Foswiki::Store::BEGIN@61
1113µs3µsFoswiki::Store::::BEGIN@62Foswiki::Store::BEGIN@62
1112µs2µsFoswiki::Store::::finishFoswiki::Store::finish
0000s0sFoswiki::Store::::__ANON__[:278]Foswiki::Store::__ANON__[:278]
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
2
3=begin TML
4
5---+ package Foswiki::Store
6
7This class is a pure virtual base class that specifies the interface
8between the actual store implementation and the rest of the Foswiki
9system.
10
11Subclasses of this class (known as "store implementations") are
12responsible for checking for topic existance, access permissions, and
13all the other general admin tasks required of a store.
14
15This class knows *nothing* about how the data is actually _stored_ -
16that knowledge is entirely encapsulated in the implementation.
17
18The general contract for methods in the class requires that errors
19are signalled using exceptions. Foswiki::AccessControlException is
20used for access control exceptions, and Error::Simple for all other
21types of error.
22
23The reference implementations of this base class
24=Foswiki::Store::PlainFileStore=,
25which can be obtained from PlainFileStoreContrib.
26
27Methods of this class and all subclasses should *only* be called from
28=Foswiki= and =Foswiki::Meta=. All other system components must delegate
29store interactions via =Foswiki::Meta=.
30
31For readers who are familiar with Foswiki version 1.0.0, this class
32_describes_ the interface to the old =Foswiki::Store= without actually
33_implementing_ it.
34
35Note that most methods are passed a Foswiki::Meta object. This pattern is
36employed to reinforce the encapsulation of a "path" in a meta object, and
37also to allow the store to modify META fields in the object, something it
38would be unable to do if passed $web, $topic.
39
40Version numbers are required to be positive, non-zero integers. When
41passing in version numbers to the methods of a store implementation, 0,
42undef and '' are treated as referring to the *latest* (most recent)
43revision of the object. Version numbers are required to increase (later
44version numbers are greater than earlier) but are *not* required to be
45sequential.
46
47*IMPORTANT:* the store must be able to handle unicode topic and
48attachment names, and unicode topic content. The store is expected
49to do any necessary encoding/decoding from/to unicode.
50
51=cut
52
53package Foswiki::Store;
54
55225µs238µs
# spent 25µs (12+13) within Foswiki::Store::BEGIN@55 which was called: # once (12µs+13µs) by Foswiki::UI::View::BEGIN@23 at line 55
use strict;
# spent 25µs making 1 call to Foswiki::Store::BEGIN@55 # spent 13µs making 1 call to strict::import
56225µs217µs
# spent 12µs (8+4) within Foswiki::Store::BEGIN@56 which was called: # once (8µs+4µs) by Foswiki::UI::View::BEGIN@23 at line 56
use warnings;
# spent 12µs making 1 call to Foswiki::Store::BEGIN@56 # spent 4µs making 1 call to warnings::import
57
58228µs2202µs
# spent 105µs (8+97) within Foswiki::Store::BEGIN@58 which was called: # once (8µs+97µs) by Foswiki::UI::View::BEGIN@23 at line 58
use Error qw( :try );
# spent 105µs making 1 call to Foswiki::Store::BEGIN@58 # spent 97µs making 1 call to Error::import
59224µs254µs
# spent 32µs (9+22) within Foswiki::Store::BEGIN@59 which was called: # once (9µs+22µs) by Foswiki::UI::View::BEGIN@23 at line 59
use Assert;
# spent 32µs making 1 call to Foswiki::Store::BEGIN@59 # spent 22µs making 1 call to Exporter::import
60
61220µs13µs
# spent 3µs within Foswiki::Store::BEGIN@61 which was called: # once (3µs+0s) by Foswiki::UI::View::BEGIN@23 at line 61
use Foswiki ();
# spent 3µs making 1 call to Foswiki::Store::BEGIN@61
62226µs13µs
# spent 3µs within Foswiki::Store::BEGIN@62 which was called: # once (3µs+0s) by Foswiki::UI::View::BEGIN@23 at line 62
use Foswiki::Sandbox ();
# spent 3µs making 1 call to Foswiki::Store::BEGIN@62
632209µs13.23ms
# spent 3.23ms (2.87+360µs) within Foswiki::Store::BEGIN@63 which was called: # once (2.87ms+360µs) by Foswiki::UI::View::BEGIN@23 at line 63
use HTML::Entities ();
# spent 3.23ms making 1 call to Foswiki::Store::BEGIN@63
64
65
# spent 5µs within Foswiki::Store::BEGIN@65 which was called: # once (5µs+0s) by Foswiki::UI::View::BEGIN@23 at line 70
BEGIN {
6615µs if ( $Foswiki::cfg{UseLocale} ) {
67 require locale;
68 import locale();
69 }
701516µs15µs}
# spent 5µs making 1 call to Foswiki::Store::BEGIN@65
71
72# Version number of the store API
731600nsour $STORE_FORMAT_VERSION = '1.2';
74
75=begin TML
76
77---++ ClassMethod new()
78
79Construct a Store module.
80
81=cut
82
83
# spent 12µs within Foswiki::Store::new which was called: # once (12µs+0s) by Foswiki::new at line 2120 of /var/www/foswikidev/core/lib/Foswiki.pm
sub new {
8411µs my $class = shift;
85
8618µs my $this = bless( {}, $class );
8714µs return $this;
88}
89
90=begin TML
91
92---++ ObjectMethod finish()
93Break circular references.
94
95=cut
96
97# Note to developers; please undef *all* fields in the object explicitly,
98# whether they are references or not. That way this method is "golden
99# documentation" of the live fields in the object.
100
# spent 2µs within Foswiki::Store::finish which was called: # once (2µs+0s) by Foswiki::Store::Rcs::Store::finish at line 77 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Store.pm
sub finish {
10115µs my $this = shift;
102}
103
104=begin TML
105
106---++ StaticMethod cleanUpRevID( $rev ) -> $integer
107
108Cleans up (maps) a user-supplied revision ID and converts it to an integer
109number that can be incremented to create a new revision number.
110
111This method should be used to sanitise user-provided revision IDs.
112
113Returns 0 if it was unable to determine a valid rev number from the
114string passed.
115
116Works with RCS format (e.g. 1.2) rev IDs and plain integer numbers.
117
118=cut
119
120
# spent 191ms (191+119µs) within Foswiki::Store::cleanUpRevID which was called 50350 times, avg 4µs/call: # 26326 times (127ms+119µs) by Foswiki::Serialise::Embedded::read at line 88 of /var/www/foswikidev/core/lib/Foswiki/Serialise/Embedded.pm, avg 5µs/call # 24019 times (64.3ms+0s) by Foswiki::Serialise::Embedded::read at line 90 of /var/www/foswikidev/core/lib/Foswiki/Serialise/Embedded.pm, avg 3µs/call # 3 times (7µs+0s) by Foswiki::REVINFO at line 25 of /var/www/foswikidev/core/lib/Foswiki/Macros/REVINFO.pm, avg 2µs/call # 2 times (9µs+0s) by Foswiki::Store::Rcs::Handler::_getTOPICINFO at line 278 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Handler.pm, avg 4µs/call
sub cleanUpRevID {
1215035011.7ms my $rev = shift;
122
123 # RCS format: 1.2, or plain integer: 2
12450350341ms1119µs if ( defined $rev && $rev =~ m/^(?:\d+\.)?(\d+)$/ ) {
# spent 119µs making 1 call to utf8::SWASHNEW
125 return $1;
126 }
127
12837µs return 0;
129}
130
131=begin TML
132
133---+++ ObjectMethod getWorkArea( $key ) -> $directorypath
134
135Gets a private directory uniquely identified by $key. The directory is
136intended as a work area for plugins.
137
138The standard is a directory named the same as "key" under
139$Foswiki::cfg{WorkingDir}/work_areas
140
141=cut
142
143
# spent 50µs (16+34) within Foswiki::Store::getWorkArea which was called: # once (16µs+34µs) by Foswiki::getWorkArea at line 4066 of /var/www/foswikidev/core/lib/Foswiki.pm
sub getWorkArea {
14411µs my ( $this, $key ) = @_;
145
146 # untaint and detect nasties. The rules are the same as for
147 # attachment names.
14813µs134µs $key = Foswiki::Sandbox::untaint( $key,
# spent 34µs making 1 call to Foswiki::Sandbox::untaint
149 \&Foswiki::Sandbox::validateAttachmentName );
1501300ns throw Error::Simple("Bad work area name $key") unless ($key);
151
15212µs my $dir = "$Foswiki::cfg{WorkingDir}/work_areas/$key";
153
15416µs unless ( -d $dir ) {
155 mkdir($dir) || throw Error::Simple(<<ERROR);
156Failed to create $key work area. Check your setting of {WorkingDir}
157in =configure=.
158ERROR
159 }
16014µs return $dir;
161}
162
163=begin TML
164
165---++ ObjectMethod getAttachmentURL( $web, $topic, $attachment, %options ) -> $url
166
167Get a URL that points at an attachment. The URL may be absolute, or
168relative to the the page being rendered (if that makes sense for the
169store implementation).
170 * =$session - the current Foswiki session
171 * =$web= - name of the web for the URL
172 * =$topic= - name of the topic
173 * =$attachment= - name of the attachment, defaults to no attachment
174 * %options - parameters to be attached to the URL
175
176Supported %options are:
177 * =topic_version= - version of topic to retrieve attachment from
178 * =attachment_version= - version of attachment to retrieve
179 * =absolute= - if the returned URL must be absolute, rather than relative
180
181If =$web= is not given, =$topic= and =$attachment= are ignored/
182If =$topic= is not given, =$attachment= is ignored.
183
184If =topic_version= is not given, the most recent revision of the topic
185should be linked. Similarly if attachment_version= is not given, the most recent
186revision of the attachment will be assumed. If =topic_version= is specified
187but =attachment_version= is not (or the specified =attachment_version= is not
188present), then the most recent version of the attachment in that topic version
189will be linked. Stores may not support =topic_version= and =attachment_version=.
190
191The default implementation is suitable for use with stores that put
192attachments in a web-visible directory, pointed at by
193$Foswiki::cfg{PubUrlPath}. As such it may also be used as a
194fallback for distributed topics (such as those in System) when content is not
195held in the store itself (e.g. if the store doesn't recognise the web it
196can call SUPER::getAttachmentURL)
197
198As required by RFC3986, the returned URL may only contain the
199allowed characters -A-Za-z0-9_.~!*\'();:@&=+$,/?%#[]
200
201=cut
202
203
# spent 365µs (336+29) within Foswiki::Store::getAttachmentURL which was called 59 times, avg 6µs/call: # 59 times (336µs+29µs) by Foswiki::getPubURL at line 1632 of /var/www/foswikidev/core/lib/Foswiki.pm, avg 6µs/call
sub getAttachmentURL {
2045968µs my ( $this, $session, $web, $topic, $attachment, %options ) = @_;
2055926µs my $url = $Foswiki::cfg{PubUrlPath} || '';
206
2075914µs18µs if ($topic) {
# spent 8µs making 1 call to Foswiki::Func::normalizeWebTopicName
208 ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( $web, $topic );
209 }
210
211598µs if ($web) {
21212µs19µs $url .= '/' . Foswiki::urlEncode($web);
# spent 9µs making 1 call to Foswiki::urlEncode
2131400ns if ($topic) {
2141900ns if ( defined $options{topic_version} ) {
215
216 # TODO: check that the given topic version exists
217 }
21812µs16µs $url .= '/' . Foswiki::urlEncode($topic);
# spent 6µs making 1 call to Foswiki::urlEncode
21911µs if ($attachment) {
2201500ns if ( defined $options{attachment_version} ) {
221
222 # TODO: check that this attachment version actually
223 # exists on the requested topic version
224 }
225
226 # TODO: check that the attachment actually exists on the
227 # topic at this revision
22812µs16µs $url .= '/' . Foswiki::urlEncode($attachment);
# spent 6µs making 1 call to Foswiki::urlEncode
229 }
230 }
231 }
232
23359100µs if ( $options{absolute} && $url !~ /^[a-z]+:/ ) {
234
235 # See http://www.ietf.org/rfc/rfc2396.txt for the definition of
236 # "absolute URI". Foswiki bastardises this definition by assuming
237 # that all relative URLs lack the <authority> component as well.
238 $url = "$session->{urlHost}$url";
239 }
240
24159154µs return $url;
242}
243
244=begin TML
245
246---++ StaticMethod decode($octets) -> $unicode
247
248Utility function to decode a binary string of octets read from
249the store and known known to be encoded using the
250currently selected {Store}{Encoding} (or UTF-8 if none is set)
251into perl characters (unicode). May die if $octets contains
252an invalid byte sequence for the encoding.
253
254=cut
255
256
# spent 3.78s (784ms+2.99) within Foswiki::Store::decode which was called 126791 times, avg 30µs/call: # 100320 times (557ms+1.71s) by Foswiki::Store::Rcs::Handler::getTopicNames at line 585 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Handler.pm, avg 23µs/call # 26327 times (223ms+1.26s) by Foswiki::Store::Rcs::Store::readTopic at line 116 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Store.pm, avg 56µs/call # 120 times (5.05ms+22.5ms) by Foswiki::Store::SearchAlgorithms::Forking::_search at line 168 of /var/www/foswikidev/core/lib/Foswiki/Store/SearchAlgorithms/Forking.pm, avg 230µs/call # 24 times (122µs+408µs) by Foswiki::Store::Rcs::Handler::getWebNames at line 638 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Handler.pm, avg 22µs/call
sub decode {
25712679119.1ms return $_[0] unless defined $_[0];
25812679131.0ms my $s = $_[0];
259126791791ms2535822.99s return Encode::decode( $Foswiki::cfg{Store}{Encoding} || 'utf-8',
# spent 2.93s making 126791 calls to Encode::decode, avg 23µs/call # spent 61.0ms making 126791 calls to Encode::FB_CROAK, avg 481ns/call
260 $s, Encode::FB_CROAK );
261}
262
263=begin TML
264
265---++ StaticMethod encode($unicode) -> $octets
266
267Utility function to encode a perl character string into
268a string of octets encoded using the currently selected
269{Store}{Encoding} (or UTF-8 if none is set). May die if
270=$unicode= cannot be represented in the {Store}{Encoding}.
271
272=cut
273
274
# spent 3.45s (843ms+2.61) within Foswiki::Store::encode which was called 132011 times, avg 26µs/call: # 105614 times (685ms+2.11s) by Foswiki::Store::Rcs::Handler::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Handler.pm:63] at line 63 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Handler.pm, avg 26µs/call # 26327 times (158ms+493ms) by Foswiki::Store::Rcs::Handler::readFile at line 1127 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Handler.pm, avg 25µs/call # 40 times (216µs+648µs) by Foswiki::Store::Rcs::Handler::getTopicNames at line 577 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Handler.pm, avg 22µs/call # 26 times (134µs+423µs) by Foswiki::Store::Rcs::Handler::getWebNames at line 636 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Handler.pm, avg 21µs/call # 4 times (16µs+53µs) by Foswiki::Store::Rcs::Store::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Store.pm:61] at line 61 of /var/www/foswikidev/core/lib/Foswiki/Store/Rcs/Store.pm, avg 17µs/call
sub encode {
27513201125.5ms return $_[0] unless defined $_[0];
27613201133.1ms my $s = $_[0];
277 return Encode::encode( $Foswiki::cfg{Store}{Encoding} || 'utf-8',
278132011919ms1320112.61s $s, sub { HTML::Entities::encode_entities( chr(shift) ) } );
# spent 2.61s making 132011 calls to Encode::encode, avg 20µs/call
279}
280
28118µs1;
282__END__