Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm |
Statements | Executed 286073 statements in 1.18s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
12164 | 1 | 1 | 645ms | 169s | subscribe | Foswiki::Contrib::MailerContrib::WebNotify::
12164 | 1 | 1 | 337ms | 170s | _subscribeTopic | Foswiki::Contrib::MailerContrib::WebNotify::
12182 | 2 | 2 | 135ms | 147ms | getSubscriber | Foswiki::Contrib::MailerContrib::WebNotify::
2 | 1 | 1 | 70.2ms | 175s | _load | Foswiki::Contrib::MailerContrib::WebNotify::
1068 | 1 | 1 | 24.2ms | 171s | parsePageSubscriptions | Foswiki::Contrib::MailerContrib::WebNotify::
3252 | 2 | 1 | 14.2ms | 14.2ms | CORE:match (opcode) | Foswiki::Contrib::MailerContrib::WebNotify::
2186 | 2 | 1 | 7.91ms | 7.91ms | CORE:regcomp (opcode) | Foswiki::Contrib::MailerContrib::WebNotify::
2138 | 3 | 1 | 6.39ms | 6.39ms | CORE:subst (opcode) | Foswiki::Contrib::MailerContrib::WebNotify::
1 | 1 | 1 | 1.79ms | 1.95ms | BEGIN@23 | Foswiki::Contrib::MailerContrib::WebNotify::
1 | 1 | 1 | 1.21ms | 1.69ms | BEGIN@24 | Foswiki::Contrib::MailerContrib::WebNotify::
2 | 1 | 1 | 399µs | 175s | new | Foswiki::Contrib::MailerContrib::WebNotify::
2 | 1 | 1 | 36µs | 36µs | CORE:qr (opcode) | Foswiki::Contrib::MailerContrib::WebNotify::
1 | 1 | 1 | 31µs | 39µs | BEGIN@15 | Foswiki::Contrib::MailerContrib::WebNotify::
1 | 1 | 1 | 29µs | 98µs | BEGIN@19 | Foswiki::Contrib::MailerContrib::WebNotify::
1 | 1 | 1 | 28µs | 38µs | BEGIN@17 | Foswiki::Contrib::MailerContrib::WebNotify::
1 | 1 | 1 | 21µs | 40µs | BEGIN@16 | Foswiki::Contrib::MailerContrib::WebNotify::
1 | 1 | 1 | 9µs | 9µs | BEGIN@21 | Foswiki::Contrib::MailerContrib::WebNotify::
1 | 1 | 1 | 9µs | 9µs | BEGIN@22 | Foswiki::Contrib::MailerContrib::WebNotify::
0 | 0 | 0 | 0s | 0s | _emailWarn | Foswiki::Contrib::MailerContrib::WebNotify::
0 | 0 | 0 | 0s | 0s | getSubscribers | Foswiki::Contrib::MailerContrib::WebNotify::
0 | 0 | 0 | 0s | 0s | isEmpty | Foswiki::Contrib::MailerContrib::WebNotify::
0 | 0 | 0 | 0s | 0s | processChange | Foswiki::Contrib::MailerContrib::WebNotify::
0 | 0 | 0 | 0s | 0s | processCompulsory | Foswiki::Contrib::MailerContrib::WebNotify::
0 | 0 | 0 | 0s | 0s | stringify | Foswiki::Contrib::MailerContrib::WebNotify::
0 | 0 | 0 | 0s | 0s | unsubscribe | Foswiki::Contrib::MailerContrib::WebNotify::
0 | 0 | 0 | 0s | 0s | writeWebNotify | Foswiki::Contrib::MailerContrib::WebNotify::
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::Contrib::MailerContrib::WebNotify | ||||
6 | Object that represents the contents of a %NOTIFYTOPIC% topic in a Foswiki web. | ||||
7 | |||||
8 | Note that =$Foswiki::Plugins::SESSION= is used to find the Foswiki session, and | ||||
9 | must be set up before this class is used. | ||||
10 | |||||
11 | =cut | ||||
12 | |||||
13 | package Foswiki::Contrib::MailerContrib::WebNotify; | ||||
14 | |||||
15 | 2 | 57µs | 2 | 47µs | # spent 39µs (31+8) within Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@15 which was called:
# once (31µs+8µs) by Foswiki::Contrib::MailerContrib::BEGIN@25 at line 15 # spent 39µs making 1 call to Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@15
# spent 8µs making 1 call to strict::import |
16 | 2 | 46µs | 2 | 60µs | # spent 40µs (21+19) within Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@16 which was called:
# once (21µs+19µs) by Foswiki::Contrib::MailerContrib::BEGIN@25 at line 16 # spent 40µs making 1 call to Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@16
# spent 20µs making 1 call to warnings::import |
17 | 2 | 58µs | 2 | 47µs | # spent 38µs (28+10) within Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@17 which was called:
# once (28µs+10µs) by Foswiki::Contrib::MailerContrib::BEGIN@25 at line 17 # spent 38µs making 1 call to Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@17
# spent 10µs making 1 call to locale::import |
18 | |||||
19 | 2 | 56µs | 2 | 166µs | # spent 98µs (29+69) within Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@19 which was called:
# once (29µs+69µs) by Foswiki::Contrib::MailerContrib::BEGIN@25 at line 19 # spent 98µs making 1 call to Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@19
# spent 69µs making 1 call to Assert::import |
20 | |||||
21 | 2 | 40µs | 1 | 9µs | # spent 9µs within Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@21 which was called:
# once (9µs+0s) by Foswiki::Contrib::MailerContrib::BEGIN@25 at line 21 # spent 9µs making 1 call to Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@21 |
22 | 2 | 38µs | 1 | 9µs | # spent 9µs within Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@22 which was called:
# once (9µs+0s) by Foswiki::Contrib::MailerContrib::BEGIN@25 at line 22 # spent 9µs making 1 call to Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@22 |
23 | 2 | 182µs | 1 | 1.95ms | # spent 1.95ms (1.79+160µs) within Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@23 which was called:
# once (1.79ms+160µs) by Foswiki::Contrib::MailerContrib::BEGIN@25 at line 23 # spent 1.95ms making 1 call to Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@23 |
24 | 2 | 2.98ms | 1 | 1.69ms | # spent 1.69ms (1.21+477µs) within Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@24 which was called:
# once (1.21ms+477µs) by Foswiki::Contrib::MailerContrib::BEGIN@25 at line 24 # spent 1.69ms making 1 call to Foswiki::Contrib::MailerContrib::WebNotify::BEGIN@24 |
25 | |||||
26 | =begin TML | ||||
27 | |||||
28 | ---++ new($web, $topic) | ||||
29 | * =$web= - web name | ||||
30 | * =$topic= - topic name | ||||
31 | * =$noexpandgroups= - True will prevent expansion of group subscriptions | ||||
32 | (False is best for checking subscriptions, but True is best for | ||||
33 | writing results back to $topic) | ||||
34 | |||||
35 | Create a new object by parsing the content of the given topic in the | ||||
36 | given web. This is the normal way to load a %NOTIFYTOPIC% topic. If the | ||||
37 | topic does not exist, it will create an empty object. | ||||
38 | |||||
39 | =cut | ||||
40 | |||||
41 | # spent 175s (399µs+175) within Foswiki::Contrib::MailerContrib::WebNotify::new which was called 2 times, avg 87.7s/call:
# 2 times (399µs+175s) by Foswiki::Contrib::MailerContrib::_isSubscribedToTopic at line 160 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib.pm, avg 87.7s/call | ||||
42 | 2 | 8µs | my ( $class, $web, $topic, $noexpandgroups ) = @_; | ||
43 | |||||
44 | 2 | 21µs | my $this = bless( {}, $class ); | ||
45 | |||||
46 | # Ensure the contrib is initialised | ||||
47 | 2 | 12µs | 2 | 19µs | Foswiki::Contrib::MailerContrib::initContrib(); # spent 19µs making 2 calls to Foswiki::Contrib::MailerContrib::initContrib, avg 9µs/call |
48 | |||||
49 | 2 | 5µs | $this->{web} = $web; | ||
50 | 2 | 4µs | $this->{topic} = $topic || $Foswiki::cfg{NotifyTopicName} || 'WebNotify'; | ||
51 | 2 | 5µs | $this->{pretext} = ''; | ||
52 | 2 | 4µs | $this->{posttext} = ''; | ||
53 | 2 | 5µs | $this->{noexpandgroups} = $noexpandgroups; | ||
54 | |||||
55 | 2 | 288µs | 2 | 681µs | if ( Foswiki::Func::topicExists( $web, $topic ) ) { # spent 681µs making 2 calls to Foswiki::Func::topicExists, avg 341µs/call |
56 | 2 | 18µs | 2 | 175s | $this->_load(); # spent 175s making 2 calls to Foswiki::Contrib::MailerContrib::WebNotify::_load, avg 87.7s/call |
57 | } | ||||
58 | |||||
59 | 2 | 23µs | return $this; | ||
60 | } | ||||
61 | |||||
62 | =begin TML | ||||
63 | |||||
64 | ---++ writeWebNotify() | ||||
65 | Write the object to the %NOTIFYTOPIC% topic it was read from. | ||||
66 | If there is a problem writing the topic (e.g. it is locked), | ||||
67 | the method will throw an exception. | ||||
68 | |||||
69 | =cut | ||||
70 | |||||
71 | sub writeWebNotify { | ||||
72 | my $this = shift; | ||||
73 | Foswiki::Func::saveTopicText( $this->{web}, $this->{topic}, | ||||
74 | $this->stringify(), 1, 1 ); | ||||
75 | } | ||||
76 | |||||
77 | =begin TML | ||||
78 | |||||
79 | ---++ getSubscriber($name, $noAdd) | ||||
80 | * =$name= - Name of subscriber (wikiname with no web or email address) | ||||
81 | * =$noAdd= - If false or undef, a new subscriber will be created for this name | ||||
82 | Get a subscriber from the list of subscribers, and return a reference | ||||
83 | to the Subscriber object. If $noAdd is true, and the subscriber is not | ||||
84 | found, undef will be returned. Otherwise a new Subscriber object will | ||||
85 | be added if necessary. | ||||
86 | |||||
87 | =cut | ||||
88 | |||||
89 | # spent 147ms (135+11.4) within Foswiki::Contrib::MailerContrib::WebNotify::getSubscriber which was called 12182 times, avg 12µs/call:
# 12180 times (135ms+11.4ms) by Foswiki::Contrib::MailerContrib::WebNotify::subscribe at line 142, avg 12µs/call
# 2 times (21µs+0s) by Foswiki::Contrib::MailerContrib::_isSubscribedToTopic at line 163 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib.pm, avg 10µs/call | ||||
90 | 12182 | 24.7ms | my ( $this, $name, $noAdd ) = @_; | ||
91 | |||||
92 | 12182 | 26.8ms | my $subscriber = $this->{subscribers}{$name}; | ||
93 | 12182 | 19.2ms | unless ( $noAdd || defined($subscriber) ) { | ||
94 | 1066 | 5.80ms | 1066 | 11.4ms | $subscriber = new Foswiki::Contrib::MailerContrib::Subscriber($name); # spent 11.4ms making 1066 calls to Foswiki::Contrib::MailerContrib::Subscriber::new, avg 11µs/call |
95 | 1066 | 4.05ms | $this->{subscribers}{$name} = $subscriber; | ||
96 | } | ||||
97 | 12182 | 71.0ms | return $subscriber; | ||
98 | } | ||||
99 | |||||
100 | =begin TML | ||||
101 | |||||
102 | ---++ getSubscribers() | ||||
103 | Get a list of all subscriber names (unsorted) | ||||
104 | |||||
105 | =cut | ||||
106 | |||||
107 | sub getSubscribers { | ||||
108 | my ($this) = @_; | ||||
109 | |||||
110 | return keys %{ $this->{subscribers} }; | ||||
111 | } | ||||
112 | |||||
113 | =begin TML | ||||
114 | |||||
115 | ---++ subscribe($name, $topics, $depth, $options) | ||||
116 | * =$name= - Name of subscriber (wikiname with no web or email address) | ||||
117 | * =$topics= - wildcard expression giving topics to subscribe to | ||||
118 | * =$depth= - Child depth to scan (default 0) | ||||
119 | * =$options= - Bitmap of Mailer::Const options | ||||
120 | Add a subscription, adding the subscriber if necessary. | ||||
121 | |||||
122 | =cut | ||||
123 | |||||
124 | # spent 169s (645ms+169) within Foswiki::Contrib::MailerContrib::WebNotify::subscribe which was called 12164 times, avg 13.9ms/call:
# 12164 times (645ms+169s) by Foswiki::Contrib::MailerContrib::WebNotify::_subscribeTopic at line 446, avg 13.9ms/call | ||||
125 | 12164 | 25.3ms | my ( $this, $name, $topics, $depth, $opts ) = @_; | ||
126 | |||||
127 | 12164 | 64.5ms | 12164 | 40.2ms | ASSERT( defined($opts) && $opts =~ /^\d*$/ ) if DEBUG; # spent 40.2ms making 12164 calls to Assert::ASSERTS_OFF, avg 3µs/call |
128 | |||||
129 | 12164 | 27.8ms | my @names = ($name); | ||
130 | 12164 | 49.5ms | unless ( $this->{noexpandgroups} ) { | ||
131 | 12164 | 63.4ms | 12164 | 4.28s | my $it = Foswiki::Func::eachGroupMember($name); # spent 4.28s making 12164 calls to Foswiki::Func::eachGroupMember, avg 352µs/call |
132 | 12164 | 18.9ms | if ($it) { | ||
133 | 2 | 7µs | @names = (); | ||
134 | 2 | 21µs | 2 | 326µs | while ( $it->hasNext() ) { # spent 326µs making 2 calls to Foswiki::AggregateIterator::hasNext, avg 163µs/call |
135 | 18 | 102µs | 18 | 5.71ms | my $member = $it->next(); # spent 5.71ms making 18 calls to Foswiki::AggregateIterator::next, avg 317µs/call |
136 | 18 | 136µs | 18 | 1.55ms | push( @names, $member ); # spent 1.55ms making 18 calls to Foswiki::AggregateIterator::hasNext, avg 86µs/call |
137 | } | ||||
138 | } | ||||
139 | } | ||||
140 | |||||
141 | 12164 | 94.1ms | foreach my $n (@names) { | ||
142 | 12180 | 70.1ms | 12180 | 147ms | my $subscriber = $this->getSubscriber($n); # spent 147ms making 12180 calls to Foswiki::Contrib::MailerContrib::WebNotify::getSubscriber, avg 12µs/call |
143 | 12180 | 73.3ms | 12180 | 776ms | my $sub = # spent 776ms making 12180 calls to Foswiki::Contrib::MailerContrib::Subscription::new, avg 64µs/call |
144 | new Foswiki::Contrib::MailerContrib::Subscription( $topics, $depth, | ||||
145 | $opts ); | ||||
146 | 12180 | 94.3ms | 12180 | 163s | $subscriber->subscribe($sub); # spent 163s making 12180 calls to Foswiki::Contrib::MailerContrib::Subscriber::subscribe, avg 13.4ms/call |
147 | } | ||||
148 | } | ||||
149 | |||||
150 | =begin TML | ||||
151 | |||||
152 | ---++ unsubscribe($name, $topics, $depth) | ||||
153 | * =$name= - Name of subscriber (wikiname with no web or email address) | ||||
154 | * =$topics= - wildcard expression giving topics to subscribe to | ||||
155 | * =$depth= - Child depth to scan (default 0) | ||||
156 | Add an unsubscription, adding the subscriber if necessary. An unsubscription | ||||
157 | is a specific request to ignore notifications for a topic for this | ||||
158 | particular subscriber. | ||||
159 | |||||
160 | =cut | ||||
161 | |||||
162 | sub unsubscribe { | ||||
163 | my ( $this, $name, $topics, $depth ) = @_; | ||||
164 | |||||
165 | my @names = ($name); | ||||
166 | unless ( $this->{noexpandgroups} ) { | ||||
167 | my $it = Foswiki::Func::eachGroupMember($name); | ||||
168 | if ($it) { | ||||
169 | @names = (); | ||||
170 | while ( $it->hasNext() ) { | ||||
171 | my $member = $it->next(); | ||||
172 | push( @names, $member ); | ||||
173 | } | ||||
174 | } | ||||
175 | } | ||||
176 | |||||
177 | foreach my $n (@names) { | ||||
178 | my $subscriber = $this->getSubscriber($n); | ||||
179 | my $sub = | ||||
180 | new Foswiki::Contrib::MailerContrib::Subscription( $topics, $depth, | ||||
181 | 0 ); | ||||
182 | $subscriber->unsubscribe($sub); | ||||
183 | } | ||||
184 | } | ||||
185 | |||||
186 | =begin TML | ||||
187 | |||||
188 | ---++ stringify() -> string | ||||
189 | Return a string representation of this object, in %NOTIFYTOPIC% format. | ||||
190 | |||||
191 | Optional =$subscribersOnly= parameter to only print the parsed subscription list. | ||||
192 | Used when running a mailnotify, where printing out the entire WebNotify topic is confusing, | ||||
193 | as it's different from the actual topic contents, but doesn't inform the user why. | ||||
194 | |||||
195 | =cut | ||||
196 | |||||
197 | sub stringify { | ||||
198 | my $this = shift; | ||||
199 | my $subscribersOnly = shift || 0; | ||||
200 | |||||
201 | my $page = ''; | ||||
202 | |||||
203 | $page .= $this->{pretext} if ( !$subscribersOnly ); | ||||
204 | foreach my $name ( sort keys %{ $this->{subscribers} } ) { | ||||
205 | my $subscriber = $this->{subscribers}{$name}; | ||||
206 | $page .= $subscriber->stringify() . "\n"; | ||||
207 | } | ||||
208 | $page .= $this->{posttext} if ( !$subscribersOnly ); | ||||
209 | |||||
210 | return $page; | ||||
211 | } | ||||
212 | |||||
213 | =begin TML | ||||
214 | |||||
215 | ---++ processChange($change, $db, $changeSet, $seenSet, $allSet) | ||||
216 | * =$change= - ref of a Foswiki::Contrib::Mailer::Change | ||||
217 | * =$db= - Foswiki::Contrib::MailerContrib::UpData database of parent references | ||||
218 | * =$changeSet= - ref of a hash mapping emails to sets of changes | ||||
219 | * =$seenSet= - ref of a hash recording indices of topics already seen | ||||
220 | * =$allSet= - ref of a hash that maps topics to email addresses for news subscriptions | ||||
221 | Find all subscribers that are interested in the given change. Only the most | ||||
222 | recent change to each topic listed in the .changes file is retained. This | ||||
223 | method does _not_ change this object. | ||||
224 | |||||
225 | =cut | ||||
226 | |||||
227 | sub processChange { | ||||
228 | my ( $this, $change, $db, $changeSet, $seenSet, $allSet ) = @_; | ||||
229 | |||||
230 | my $topic = $change->{TOPIC}; | ||||
231 | my $web = $change->{WEB}; | ||||
232 | my %authors = map { $_ => 1 } @{ | ||||
233 | Foswiki::Contrib::MailerContrib::Subscriber::getEmailAddressesForUser( | ||||
234 | $change->{author} | ||||
235 | ) | ||||
236 | }; | ||||
237 | |||||
238 | foreach my $name ( keys %{ $this->{subscribers} } ) { | ||||
239 | my $subscriber = $this->{subscribers}{$name}; | ||||
240 | my $subs = $subscriber->isSubscribedTo( $topic, $db ); | ||||
241 | if ( $subs && !$subscriber->isUnsubscribedFrom( $topic, $db ) ) { | ||||
242 | |||||
243 | next | ||||
244 | unless Foswiki::Func::checkAccessPermission( 'VIEW', $name, undef, | ||||
245 | $topic, $this->{web}, undef ); | ||||
246 | |||||
247 | my $emails = $subscriber->getEmailAddresses(); | ||||
248 | if ( $emails && scalar(@$emails) ) { | ||||
249 | foreach my $email (@$emails) { | ||||
250 | |||||
251 | # Skip this change if the subscriber is the author | ||||
252 | # of the change, and we are not always sending | ||||
253 | next | ||||
254 | if ( | ||||
255 | !( | ||||
256 | $subs->{options} & | ||||
257 | Foswiki::Contrib::MailerContrib::Subscription::ALWAYS | ||||
258 | ) | ||||
259 | && $authors{$email} | ||||
260 | ); | ||||
261 | |||||
262 | if ( $subs->{options} & | ||||
263 | Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC | ||||
264 | ) | ||||
265 | { | ||||
266 | push( @{ $allSet->{$topic} }, $email ); | ||||
267 | } | ||||
268 | else { | ||||
269 | my $at = $seenSet->{$email}{$topic}; | ||||
270 | if ($at) { | ||||
271 | $changeSet->{$email}[ $at - 1 ]->merge($change); | ||||
272 | } | ||||
273 | else { | ||||
274 | $seenSet->{$email}{$topic} = | ||||
275 | push( @{ $changeSet->{$email} }, $change ); | ||||
276 | } | ||||
277 | } | ||||
278 | } | ||||
279 | } | ||||
280 | else { | ||||
281 | $this->_emailWarn( $subscriber, $name, $web ); | ||||
282 | } | ||||
283 | } | ||||
284 | } | ||||
285 | } | ||||
286 | |||||
287 | =begin TML | ||||
288 | |||||
289 | ---++ processCompulsory($topic, $db, \%allSet) | ||||
290 | * =$topic= - topic name | ||||
291 | * =$db= - Foswiki::Contrib::MailerContrib::UpData database of parent references | ||||
292 | * =\%allSet= - ref of a hash that maps topics to email addresses for news subscriptions | ||||
293 | |||||
294 | =cut | ||||
295 | |||||
296 | sub processCompulsory { | ||||
297 | my ( $this, $topic, $db, $allSet ) = @_; | ||||
298 | |||||
299 | foreach my $name ( keys %{ $this->{subscribers} } ) { | ||||
300 | my $subscriber = $this->{subscribers}{$name}; | ||||
301 | my $subs = $subscriber->isSubscribedTo( $topic, $db ); | ||||
302 | next unless $subs; | ||||
303 | next | ||||
304 | unless ( $subs->{options} & | ||||
305 | Foswiki::Contrib::MailerContrib::Subscription::ALWAYS ); | ||||
306 | unless ( $subscriber->isUnsubscribedFrom( $topic, $db ) ) { | ||||
307 | my $emails = $subscriber->getEmailAddresses(); | ||||
308 | if ($emails) { | ||||
309 | foreach my $address (@$emails) { | ||||
310 | push( @{ $allSet->{$topic} }, $address ); | ||||
311 | } | ||||
312 | } | ||||
313 | } | ||||
314 | } | ||||
315 | } | ||||
316 | |||||
317 | =begin TML | ||||
318 | |||||
319 | ---++ isEmpty() -> boolean | ||||
320 | Return true if there are no subscribers | ||||
321 | |||||
322 | =cut | ||||
323 | |||||
324 | sub isEmpty { | ||||
325 | my $this = shift; | ||||
326 | return ( scalar( keys %{ $this->{subscribers} } ) == 0 ); | ||||
327 | } | ||||
328 | |||||
329 | # PRIVATE parse a topic extracting formatted lines | ||||
330 | # spent 175s (70.2ms+175) within Foswiki::Contrib::MailerContrib::WebNotify::_load which was called 2 times, avg 87.7s/call:
# 2 times (70.2ms+175s) by Foswiki::Contrib::MailerContrib::WebNotify::new at line 56, avg 87.7s/call | ||||
331 | 2 | 3µs | my $this = shift; | ||
332 | |||||
333 | 2 | 27µs | 2 | 3.16s | my ( $meta, $text ) = # spent 3.16s making 2 calls to Foswiki::Func::readTopic, avg 1.58s/call |
334 | Foswiki::Func::readTopic( $this->{web}, $this->{topic} ); | ||||
335 | 2 | 4µs | my $in_pre = 1; | ||
336 | 2 | 9µs | $this->{pretext} = ''; | ||
337 | 2 | 5µs | $this->{posttext} = ''; | ||
338 | 2 | 9µs | $this->{meta} = $meta; | ||
339 | |||||
340 | # join \ terminated lines | ||||
341 | 2 | 278µs | 2 | 252µs | $text =~ s/\\\r?\n//gs; # spent 252µs making 2 calls to Foswiki::Contrib::MailerContrib::WebNotify::CORE:subst, avg 126µs/call |
342 | 2 | 109µs | 4 | 71µs | my $webRE = qr/(?:$Foswiki::cfg{UsersWebName}\.)?/; # spent 36µs making 2 calls to Foswiki::Contrib::MailerContrib::WebNotify::CORE:qr, avg 18µs/call
# spent 35µs making 2 calls to Foswiki::Contrib::MailerContrib::WebNotify::CORE:regcomp, avg 18µs/call |
343 | 2 | 1.44ms | foreach my $baseline ( split( /\r?\n/, $text ) ) { | ||
344 | 1092 | 8.32ms | 1092 | 1.24s | my $line = # spent 1.24s making 1092 calls to Foswiki::Func::expandCommonVariables, avg 1.14ms/call |
345 | Foswiki::Func::expandCommonVariables( $baseline, $this->{topic}, | ||||
346 | $this->{web}, $meta ); | ||||
347 | 1092 | 45.0ms | 4368 | 20.3ms | if ( # spent 12.4ms making 2184 calls to Foswiki::Contrib::MailerContrib::WebNotify::CORE:match, avg 6µs/call
# spent 7.88ms making 2184 calls to Foswiki::Contrib::MailerContrib::WebNotify::CORE:regcomp, avg 4µs/call |
348 | $line =~ m{ | ||||
349 | ^\s+\*\s$webRE | ||||
350 | ($Foswiki::regex{wikiWordRegex}) | ||||
351 | \s+\-\s+ | ||||
352 | ($Foswiki::cfg{MailerContrib}{EmailFilterIn}+) | ||||
353 | \s*$}x | ||||
354 | && $1 ne $Foswiki::cfg{DefaultUserWikiName} | ||||
355 | ) | ||||
356 | { | ||||
357 | |||||
358 | # Main.WikiName - email@domain (legacy format) | ||||
359 | $this->subscribe( $2, '*', 0, 0 ); | ||||
360 | $in_pre = 0; | ||||
361 | } | ||||
362 | elsif ( | ||||
363 | $line =~ m{ | ||||
364 | ^\s+\*\s$webRE | ||||
365 | ( | ||||
366 | $Foswiki::regex{wikiWordRegex} | ||||
367 | | '.*?' | ||||
368 | | ".*?" | ||||
369 | | $Foswiki::cfg{MailerContrib}{EmailFilterIn} | ||||
370 | ) | ||||
371 | \s*(:.*)?$ | ||||
372 | }x | ||||
373 | && $1 ne $Foswiki::cfg{DefaultUserWikiName} | ||||
374 | ) | ||||
375 | { | ||||
376 | 1068 | 2.59ms | my $subscriber = $1; | ||
377 | |||||
378 | # Get the topic list from the last bracket matched. Have to do it | ||||
379 | # this awkward way because the email filter may contain braces | ||||
380 | 1068 | 2.30ms | my $topics = $+; | ||
381 | |||||
382 | # email addresses can't start with : | ||||
383 | 1068 | 9.07ms | 1068 | 3.62ms | $topics = undef unless ( $topics =~ s/^:// ); # spent 3.62ms making 1068 calls to Foswiki::Contrib::MailerContrib::WebNotify::CORE:subst, avg 3µs/call |
384 | 1068 | 7.08ms | 1068 | 2.52ms | $subscriber =~ s/^(['"])(.*)\1$/$2/; # remove quotes # spent 2.52ms making 1068 calls to Foswiki::Contrib::MailerContrib::WebNotify::CORE:subst, avg 2µs/call |
385 | |||||
386 | # CDot: I don't understand how this can ever be tainted, but the | ||||
387 | # unit tests fail without this untaint. The subscriber is | ||||
388 | # validated, and should be untainted, by the conditional regex. | ||||
389 | 1068 | 6.54ms | 1068 | 18.8ms | $subscriber = Foswiki::Sandbox::untaintUnchecked($subscriber); # spent 18.8ms making 1068 calls to Foswiki::Sandbox::untaintUnchecked, avg 18µs/call |
390 | |||||
391 | 1068 | 3.03ms | if ( defined $topics ) { | ||
392 | 1068 | 5.98ms | 1068 | 171s | $this->parsePageSubscriptions( $subscriber, $topics ); # spent 171s making 1068 calls to Foswiki::Contrib::MailerContrib::WebNotify::parsePageSubscriptions, avg 160ms/call |
393 | } | ||||
394 | else { | ||||
395 | $this->subscribe( $subscriber, '*', 0, 0 ); | ||||
396 | } | ||||
397 | 1068 | 2.31ms | $in_pre = 0; | ||
398 | } | ||||
399 | else { | ||||
400 | 24 | 63µs | if ($in_pre) { | ||
401 | 22 | 95µs | $this->{pretext} .= "$baseline\n"; | ||
402 | } | ||||
403 | else { | ||||
404 | 2 | 18µs | $this->{posttext} .= "$baseline\n"; | ||
405 | } | ||||
406 | } | ||||
407 | } | ||||
408 | } | ||||
409 | |||||
410 | # parse a pages list, adding subscriptions as appropriate | ||||
411 | # $unsubscribe is set to '-' by SubscribePlugin to force a '-' operation | ||||
412 | # spent 171s (24.2ms+171) within Foswiki::Contrib::MailerContrib::WebNotify::parsePageSubscriptions which was called 1068 times, avg 160ms/call:
# 1068 times (24.2ms+171s) by Foswiki::Contrib::MailerContrib::WebNotify::_load at line 392, avg 160ms/call | ||||
413 | 1068 | 3.26ms | my ( $this, $who, $spec, $unsubscribe ) = @_; | ||
414 | |||||
415 | 1068 | 2.68ms | $this->{topicSub} = \&_subscribeTopic; | ||
416 | |||||
417 | 1068 | 6.88ms | 1068 | 0s | my $ret = # spent 171s making 1068 calls to Foswiki::Contrib::MailerContrib::parsePageList, avg 160ms/call, recursion: max depth 1, sum of overlapping time 171s |
418 | Foswiki::Contrib::MailerContrib::parsePageList( $this, $who, $spec, | ||||
419 | $unsubscribe ); | ||||
420 | 1068 | 6.88ms | 1068 | 1.79ms | if ( $ret =~ m/\S/ ) { # spent 1.79ms making 1068 calls to Foswiki::Contrib::MailerContrib::WebNotify::CORE:match, avg 2µs/call |
421 | Foswiki::Func::writeWarning("Badly formatted page list at $who: $spec"); | ||||
422 | return -1; | ||||
423 | } | ||||
424 | 1068 | 5.73ms | return; | ||
425 | } | ||||
426 | |||||
427 | # spent 170s (337ms+170) within Foswiki::Contrib::MailerContrib::WebNotify::_subscribeTopic which was called 12164 times, avg 14.0ms/call:
# 12164 times (337ms+170s) by Foswiki::Contrib::MailerContrib::parsePageList at line 210 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib.pm, avg 14.0ms/call | ||||
428 | 12164 | 28.9ms | my ( $this, $who, $unsubscribe, $webTopic, $options, $childDepth ) = @_; | ||
429 | |||||
430 | 12164 | 74.9ms | 12164 | 739ms | my ( $web, $topic ) = # spent 739ms making 12164 calls to Foswiki::Func::normalizeWebTopicName, avg 61µs/call |
431 | Foswiki::Func::normalizeWebTopicName( $this->{web}, $webTopic ); | ||||
432 | |||||
433 | #print STDERR "_subscribeTopic($topic)\n"; | ||||
434 | 12164 | 16.3ms | my $opts = 0; | ||
435 | 12164 | 15.5ms | if ($options) { | ||
436 | $opts |= Foswiki::Contrib::MailerContrib::Subscription::FULL_TOPIC; | ||||
437 | if ( $options =~ /!/ ) { | ||||
438 | $opts |= Foswiki::Contrib::MailerContrib::Subscription::ALWAYS; | ||||
439 | } | ||||
440 | } | ||||
441 | 12164 | 16.1ms | my $kids = $childDepth or 0; | ||
442 | 12164 | 38.8ms | if ( $unsubscribe && $unsubscribe eq '-' ) { | ||
443 | $this->unsubscribe( $who, $topic, $kids ); | ||||
444 | } | ||||
445 | else { | ||||
446 | 12164 | 67.6ms | 12164 | 169s | $this->subscribe( $who, $topic, $kids, $opts ); # spent 169s making 12164 calls to Foswiki::Contrib::MailerContrib::WebNotify::subscribe, avg 13.9ms/call |
447 | } | ||||
448 | |||||
449 | #TODO: howto find & report errors? | ||||
450 | 12164 | 61.6ms | return ''; | ||
451 | } | ||||
452 | |||||
453 | # PRIVATE emailWarn to warn when an email address cannot be found | ||||
454 | # for a subscriber. | ||||
455 | sub _emailWarn { | ||||
456 | my ( $this, $subscriber, $name, $web ) = @_; | ||||
457 | |||||
458 | # Make sure we only warn once. Don't want to see this for every | ||||
459 | # Topic we are notifying on. | ||||
460 | unless ( defined $this->{nomail}{$name} ) { | ||||
461 | $this->{nomail}{$name} = 1; | ||||
462 | Foswiki::Func::writeWarning( "Failed to find permitted email for '" | ||||
463 | . $subscriber->stringify() | ||||
464 | . "' when processing web '$web'" ); | ||||
465 | } | ||||
466 | } | ||||
467 | |||||
468 | 1 | 4µs | 1; | ||
469 | __END__ | ||||
# spent 14.2ms within Foswiki::Contrib::MailerContrib::WebNotify::CORE:match which was called 3252 times, avg 4µs/call:
# 2184 times (12.4ms+0s) by Foswiki::Contrib::MailerContrib::WebNotify::_load at line 347, avg 6µs/call
# 1068 times (1.79ms+0s) by Foswiki::Contrib::MailerContrib::WebNotify::parsePageSubscriptions at line 420, avg 2µs/call | |||||
# spent 36µs within Foswiki::Contrib::MailerContrib::WebNotify::CORE:qr which was called 2 times, avg 18µs/call:
# 2 times (36µs+0s) by Foswiki::Contrib::MailerContrib::WebNotify::_load at line 342, avg 18µs/call | |||||
# spent 7.91ms within Foswiki::Contrib::MailerContrib::WebNotify::CORE:regcomp which was called 2186 times, avg 4µs/call:
# 2184 times (7.88ms+0s) by Foswiki::Contrib::MailerContrib::WebNotify::_load at line 347, avg 4µs/call
# 2 times (35µs+0s) by Foswiki::Contrib::MailerContrib::WebNotify::_load at line 342, avg 18µs/call | |||||
# spent 6.39ms within Foswiki::Contrib::MailerContrib::WebNotify::CORE:subst which was called 2138 times, avg 3µs/call:
# 1068 times (3.62ms+0s) by Foswiki::Contrib::MailerContrib::WebNotify::_load at line 383, avg 3µs/call
# 1068 times (2.52ms+0s) by Foswiki::Contrib::MailerContrib::WebNotify::_load at line 384, avg 2µs/call
# 2 times (252µs+0s) by Foswiki::Contrib::MailerContrib::WebNotify::_load at line 341, avg 126µs/call |