← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/bin/epoll_server.pl
  Run on Wed Jan 5 05:34:33 2011
Reported on Wed Jan 5 05:43:21 2011

File /usr/lib/perl5/vendor_perl/5.10.1/Epoll/DB.pm
Statements Executed 34
Statement Execution Time 7.82ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11118.6ms363msEpoll::DB::::BEGIN@8Epoll::DB::BEGIN@8
975294µs62.0msEpoll::DB::::pollEpoll::DB::poll
111183µs304µsEpoll::DB::::BEGIN@6Epoll::DB::BEGIN@6
11154µs170µsEpoll::DB::::BEGIN@5Epoll::DB::BEGIN@5
11153µs275msEpoll::DB::::newEpoll::DB::new
11133µs7.01msEpoll::DB::::BEGIN@7Epoll::DB::BEGIN@7
0000s0sEpoll::DB::::_create_pollEpoll::DB::_create_poll
0000s0sEpoll::DB::::addupd_votingEpoll::DB::addupd_voting
0000s0sEpoll::DB::::auth_pollEpoll::DB::auth_poll
0000s0sEpoll::DB::::auth_votingEpoll::DB::auth_voting
0000s0sEpoll::DB::::ballotEpoll::DB::ballot
0000s0sEpoll::DB::::ballot_countEpoll::DB::ballot_count
0000s0sEpoll::DB::::ballot_count_nonullEpoll::DB::ballot_count_nonull
0000s0sEpoll::DB::::ballot_infoEpoll::DB::ballot_info
0000s0sEpoll::DB::::ballot_itemsEpoll::DB::ballot_items
0000s0sEpoll::DB::::choice_infoEpoll::DB::choice_info
0000s0sEpoll::DB::::clean_old_poll_requestEpoll::DB::clean_old_poll_request
0000s0sEpoll::DB::::create_pollEpoll::DB::create_poll
0000s0sEpoll::DB::::create_poll_requestEpoll::DB::create_poll_request
0000s0sEpoll::DB::::delete_choiceEpoll::DB::delete_choice
0000s0sEpoll::DB::::delete_pollEpoll::DB::delete_poll
0000s0sEpoll::DB::::delete_votingEpoll::DB::delete_voting
0000s0sEpoll::DB::::find_poll_by_notyet_votingEpoll::DB::find_poll_by_notyet_voting
0000s0sEpoll::DB::::find_poll_by_ownerEpoll::DB::find_poll_by_owner
0000s0sEpoll::DB::::find_poll_by_votingEpoll::DB::find_poll_by_voting
0000s0sEpoll::DB::::list_closed_voteEpoll::DB::list_closed_vote
0000s0sEpoll::DB::::list_coming_voteEpoll::DB::list_coming_vote
0000s0sEpoll::DB::::list_running_voteEpoll::DB::list_running_vote
0000s0sEpoll::DB::::list_vote_ballotEpoll::DB::list_vote_ballot
0000s0sEpoll::DB::::list_vote_ballot_needvalidEpoll::DB::list_vote_ballot_needvalid
0000s0sEpoll::DB::::mark_ballot_invalidEpoll::DB::mark_ballot_invalid
0000s0sEpoll::DB::::poll_from_requestEpoll::DB::poll_from_request
0000s0sEpoll::DB::::poll_request_infoEpoll::DB::poll_request_info
0000s0sEpoll::DB::::register_ballotEpoll::DB::register_ballot
0000s0sEpoll::DB::::resultsEpoll::DB::results
0000s0sEpoll::DB::::signing_countEpoll::DB::signing_count
0000s0sEpoll::DB::::vote_add_choiceEpoll::DB::vote_add_choice
0000s0sEpoll::DB::::vote_ballot_countEpoll::DB::vote_ballot_count
0000s0sEpoll::DB::::vote_ballot_count_nonullEpoll::DB::vote_ballot_count_nonull
0000s0sEpoll::DB::::vote_ballot_untrusted_valuesEpoll::DB::vote_ballot_untrusted_values
0000s0sEpoll::DB::::vote_ballot_valuesEpoll::DB::vote_ballot_values
0000s0sEpoll::DB::::vote_choicesEpoll::DB::vote_choices
0000s0sEpoll::DB::::vote_infoEpoll::DB::vote_info
0000s0sEpoll::DB::::vote_map_valueEpoll::DB::vote_map_value
0000s0sEpoll::DB::::vote_paramEpoll::DB::vote_param
0000s0sEpoll::DB::::vote_results_countEpoll::DB::vote_results_count
0000s0sEpoll::DB::::vote_results_nonullEpoll::DB::vote_results_nonull
0000s0sEpoll::DB::::vote_set_settingsEpoll::DB::vote_set_settings
0000s0sEpoll::DB::::vote_signingEpoll::DB::vote_signing
0000s0sEpoll::DB::::vote_signing_countEpoll::DB::vote_signing_count
0000s0sEpoll::DB::::vote_statusEpoll::DB::vote_status
0000s0sEpoll::DB::::vote_votingEpoll::DB::vote_voting
0000s0sEpoll::DB::::vote_voting_countEpoll::DB::vote_voting_count
0000s0sEpoll::DB::::voting_from_fileEpoll::DB::voting_from_file
0000s0sEpoll::DB::::voting_has_signEpoll::DB::voting_has_sign
0000s0sEpoll::DB::::voting_infoEpoll::DB::voting_info
0000s0sEpoll::DB::::voting_info_idEpoll::DB::voting_info_id
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Epoll::DB;
2
3# $Id: DB.pm 337 2010-10-05 22:43:38Z misc $
4
53340µs2286µs
# spent 170µs (54+116) within Epoll::DB::BEGIN@5 which was called # once (54µs+116µs) by Epoll::View::TT::BEGIN@6 at line 5
use strict;
# spent 170µs making 1 call to Epoll::DB::BEGIN@5 # spent 116µs making 1 call to strict::import
63155µs2425µs
# spent 304µs (183+121) within Epoll::DB::BEGIN@6 which was called # once (183µs+121µs) by Epoll::View::TT::BEGIN@6 at line 6
use warnings;
# spent 304µs making 1 call to Epoll::DB::BEGIN@6 # spent 121µs making 1 call to warnings::import
7394µs214.0ms
# spent 7.01ms (33µs+6.98) within Epoll::DB::BEGIN@7 which was called # once (33µs+6.98ms) by Epoll::View::TT::BEGIN@6 at line 7
use base 'Epoll::DB::common';
# spent 7.01ms making 1 call to Epoll::DB::BEGIN@7 # spent 6.98ms making 1 call to base::import
836.58ms2363ms
# spent 363ms (18.6+345) within Epoll::DB::BEGIN@8 which was called # once (18.6ms+345ms) by Epoll::View::TT::BEGIN@6 at line 8
use Epoll::DB::Poll;
# spent 363ms making 1 call to Epoll::DB::BEGIN@8 # spent 83µs making 1 call to Exporter::import
9
1013µsour $VERSION = '1.90';
11
12=head1 NAME
13
14Epoll::Model::Vote - Catalyst Model
15
16=head1 DESCRIPTION
17
18Catalyst Model.
19
20=cut
21
22
# spent 275ms (53µs+275) within Epoll::DB::new which was called # once (53µs+275ms) by Epoll::Model::Vote::new at line 21 of Epoll/Model/Vote.pm
sub new {
2315µs my ($class, $dbstring) = @_;
24
25144µs1275ms bless {
# spent 275ms making 1 call to Epoll::DB::common::_newdb
26 dbstring => $dbstring,
27 db => Epoll::DB::common::_newdb($dbstring),
28 }, $class;
29}
30
31sub list_coming_vote {
32 my ($self) = @_;
33
34 my $sth = $self->db->prepare_cached(
35 q{
36 select id from poll where
37 (start > now() and "end" > now()) or
38 "end" is null or start is null
39 }
40 );
41
42 $sth->execute;
43 my @id;
44 while(my $res = $sth->fetchrow_hashref) {
45 push(@id, $res->{id});
46 }
47
48 @id
49}
50
51sub list_running_vote {
52 my ($self) = @_;
53
54 my $sth = $self->db->prepare_cached(
55 q{
56 select id from poll where start < now() and "end" > now()
57 }
58 );
59
60 $sth->execute;
61 my @id;
62 while(my $res = $sth->fetchrow_hashref) {
63 push(@id, $res->{id});
64 }
65
66 @id
67}
68
69sub list_closed_vote {
70 my ($self) = @_;
71
72 my $sth = $self->db->prepare_cached(
73 q{
74 select id from poll where
75 start < now() and "end" < now()
76 }
77 );
78
79 $sth->execute;
80 my @id;
81 while(my $res = $sth->fetchrow_hashref) {
82 push(@id, $res->{id});
83 }
84
85 @id
86}
87
88
# spent 62.0ms (294µs+61.7) within Epoll::DB::poll which was called 9 times, avg 6.89ms/call: # 3 times (94µs+12.1ms) by Template::Stash::XS::get at line 1 of Epoll/root/mail/voting_passwd.tt, avg 4.07ms/call # once (73µs+28.7ms) by Epoll::Controller::Admin::voters at line 188 of Epoll/Controller/Admin.pm # once (42µs+7.07ms) by Template::Stash::XS::get at line 2 of Epoll/root/templates/includes/admin_menu.tt # once (34µs+6.59ms) by Epoll::Controller::Admin::auth at line 152 of Epoll/Controller/Admin.pm # once (21µs+2.69ms) by Template::Stash::XS::get at line 30 of Epoll/root/templates/includes/header.tt # once (14µs+2.32ms) by Template::Stash::XS::get at line 2 of Epoll/root/templates/admin/voters.tt # once (16µs+2.28ms) by Template::Stash::XS::get at line 45 of Epoll/root/templates/includes/header.tt
sub poll {
89923µs my ($self, $pollid) = @_;
909526µs1861.7ms Epoll::DB::Poll->new($self->{dbstring}, $self->poll_id_from_uid($pollid));
# spent 34.9ms making 9 calls to Epoll::DB::Poll::new, avg 3.88ms/call # spent 26.8ms making 9 calls to Epoll::DB::common::poll_id_from_uid, avg 2.98ms/call
91}
92
93sub results {
94 my ($self, $pollid) = @_;
95 Epoll::DB::Poll->new($self->{dbstring}, $self->poll_id_from_uid($pollid));
96}
97
98# This part is keep to track error
99sub ballot {die "# ballot" . join(' ',caller());}
100sub vote_param { die "# vote_param" . join(' ',caller());}
101sub vote_status {die "# vote_status" . join(' ',caller());}
102sub vote_info {die "# vote_info" . join(' ',caller());}
103sub vote_set_settings {die "# old functions" . join(' ',caller());}
104sub vote_signing {die "# old functions" . join(' ',caller());}
105sub vote_voting {die "# old functions" . join(' ',caller());}
106sub voting_info {die "# old functions" . join(' ',caller());}
107sub vote_choices {die "# old functions" . join(' ',caller());}
108sub vote_add_choice {die "# old functions" . join(' ',caller());}
109sub choice_info {die "# old functions" . join(' ',caller());}
110sub delete_choice {die "# old functions" . join(' ',caller());}
111sub voting_info_id {die "# old functions" . join(' ',caller());}
112sub register_ballot {die "# old functions" . join(' ',caller());}
113sub vote_voting_count {die "# old functions" . join(' ',caller());}
114sub signing_count { vote_signing_count(@_) }
115sub vote_signing_count {die "# old functions" . join(' ',caller());}
116sub ballot_count { vote_ballot_count(@_) }
117sub vote_ballot_count {die "# old functions" . join(' ',caller());}
118sub ballot_count_nonull { vote_ballot_count_nonull(@_) }
119sub vote_ballot_count_nonull {die "# old functions" . join(' ',caller());}
120sub auth_voting {die "# old functions" . join(' ',caller());}
121sub auth_poll {die "# old functions" . join(' ',caller());}
122sub voting_has_sign {die "# old functions" . join(' ',caller());}
123sub vote_results_count {die "# old functions" . join(' ',caller());}
124sub vote_results_nonull {die "# old functions" . join(' ',caller());}
125sub list_vote_ballot {die "# old functions" . join(' ',caller());}
126sub list_vote_ballot_needvalid {die "# old functions" . join(' ',caller());}
127sub ballot_info {die "# vote_status" . join(' ',caller());}
128sub mark_ballot_invalid {die "# old functions" . join(' ',caller());}
129sub ballot_items {die "# old functions" . join(' ',caller());}
130sub vote_ballot_untrusted_values {die "# old functions" . join(' ',caller());}
131sub vote_ballot_values {die "# old functions" . join(' ',caller());}
132sub vote_map_value {die "# old functions" . join(' ',caller());}
133sub addupd_voting {die "# old functions" . join(' ',caller());}
134sub delete_voting {die "# old functions" . join(' ',caller());}
135sub voting_from_file {die "# old functions" . join(' ',caller());}
136
137sub clean_old_poll_request {
138 my ($self) = @_;
139 $self->db->do(q{delete from poll_request where "create" < now() - '30 days'::interval});
140}
141
142sub poll_request_info {
143 my ($self, $rid) = @_;
144
145 my $sth = $self->db->prepare_cached(
146 q{select * from poll_request where id = ?}
147 );
148
149 $sth->execute($rid);
150 my $res = $sth->fetchrow_hashref;
151 $sth->finish;
152 $res
153}
154
155sub poll_from_request {
156 my ($self, $rid, $passwd) = @_;
157 my $rinfo = $self->poll_request_info($rid) or return;
158
159 my $pollid = $self->_create_poll($rinfo->{mail}, $rinfo->{label}, $passwd);
160
161 my $delreq = $self->db->prepare_cached(
162 q{delete from poll_request where id = ?}
163 );
164
165 $delreq->execute($rid);
166 $self->commit;
167 $pollid
168}
169
170sub create_poll {
171 my ($self, @args) = @_;
172 my $uid = $self->_create_poll(@args);
173 $self->commit;
174 $uid;
175}
176
177sub _create_poll {
178 my ($self, $mail, $label, $passwd) = @_;
179
180 my $encpasswd = $self->gen_enc_passwd($passwd);
181
182 my $getpollid = $self->db->prepare_cached(
183 q{select nextval('poll_id_seq')}
184 );
185 $getpollid->execute();
186 my $newpollid = $getpollid->fetchrow_hashref->{nextval};
187 $getpollid->finish;
188
189 my $newpoll = $self->db->prepare_cached(
190 q{insert into poll (id, label, owner, password) values (?,?,?,?)}
191 );
192
193 $newpoll->execute($newpollid, $label, $mail, $encpasswd);
194 # set some default
195 $self->poll($newpollid)->setup() or do {
196 $self->rollback;
197 return;
198 };
199
200 $newpollid
201}
202
203
204sub create_poll_request {
205 my ($self, %info) = @_;
206
207 $info{mail} or return;
208 my $addreq = $self->db->prepare_cached(
209 q{insert into poll_request (id, label, mail) values (?,?,?)}
210 );
211
212 my $reqid = Epoll::DB::common::gen_uid();
213
214 $addreq->execute($reqid, $info{label}, $info{mail});
215 $self->commit;
216 $reqid;
217}
218
219sub find_poll_by_voting {
220 my ($self, $mail) = @_;
221 $mail or return;
222 my $finder = $self->db->prepare_cached(q{
223 select poll.id, date from poll join
224 subpoll on poll.id = subpoll.pollid
225 join voters on voters.poll = poll.id
226 left join signing on
227 signing.subpoll = subpoll.id and
228 signing.voters = voters.key
229 where mail = lower($1)
230 group by poll.id, date
231 order by date desc
232 }
233 );
234 $finder->execute($mail);
235 my @results;
236 while (my $res = $finder->fetchrow_hashref) {
237 push(@results, $res);
238 }
239 @results
240}
241
242sub find_poll_by_notyet_voting {
243 my ($self, $mail) = @_;
244 $mail or return;
245 my $finder = $self->db->prepare_cached(
246 q{select poll from voting where
247 key not in (select key from signing)
248 and
249 poll in (select id from poll where "end" > now())
250 and
251 mail = lower($1)
252 }
253 );
254 $finder->execute($mail);
255 my @results;
256 while (my $res = $finder->fetchrow_hashref) {
257 push(@results, $res);
258 }
259 @results
260}
261
262sub find_poll_by_owner {
263 my ($self, $mail) = @_;
264 $mail or return;
265 my $finder = $self->db->prepare_cached(
266 q{select id, "end" > now() as terminated from poll where owner = lower($1)
267 order by "end" desc}
268 );
269 $finder->execute($mail);
270 my @results;
271 while (my $res = $finder->fetchrow_hashref) {
272 push(@results, $res);
273 }
274 @results
275}
276
277sub delete_poll {
278 my ($self, $id) = @_;
279 {
280 my $poll = $self->poll($id);
281 $poll->_delete_ballot;
282 }
283
284 foreach (
285 q{delete from settings where poll = ?},
286 q{delete from signing where key in (select key from voting where poll = ?)},
287 q{delete from voting where poll = ?},
288 q{delete from choice where poll = ?},
289 q{delete from ballot_map where poll = ?},
290 q{delete from poll where id = ?},
291 ) {
292 my $req = $self->db->prepare($_);
293 $req->execute($id) or do {
294 $self->rollback;
295 return;
296 };
297 }
298
299 $self->commit;
300 return 1;
301}
302
303=head1 AUTHOR
304
305Thauvin Olivier
306
307=head1 LICENSE
308
309This library is free software, you can redistribute it and/or modify
310it under the same terms as Perl itself or CeCILL.
311
312=cut
313
314158µs1;