| File | /usr/lib/perl5/vendor_perl/5.10.1/Epoll/DB.pm |
| Statements Executed | 34 |
| Statement Execution Time | 7.82ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 18.6ms | 363ms | Epoll::DB::BEGIN@8 |
| 9 | 7 | 5 | 294µs | 62.0ms | Epoll::DB::poll |
| 1 | 1 | 1 | 183µs | 304µs | Epoll::DB::BEGIN@6 |
| 1 | 1 | 1 | 54µs | 170µs | Epoll::DB::BEGIN@5 |
| 1 | 1 | 1 | 53µs | 275ms | Epoll::DB::new |
| 1 | 1 | 1 | 33µs | 7.01ms | Epoll::DB::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::_create_poll |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::addupd_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::auth_poll |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::auth_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::ballot |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::ballot_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::ballot_count_nonull |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::ballot_info |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::ballot_items |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::choice_info |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::clean_old_poll_request |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::create_poll |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::create_poll_request |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::delete_choice |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::delete_poll |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::delete_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::find_poll_by_notyet_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::find_poll_by_owner |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::find_poll_by_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::list_closed_vote |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::list_coming_vote |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::list_running_vote |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::list_vote_ballot |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::list_vote_ballot_needvalid |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::mark_ballot_invalid |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::poll_from_request |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::poll_request_info |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::register_ballot |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::results |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::signing_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_add_choice |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_ballot_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_ballot_count_nonull |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_ballot_untrusted_values |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_ballot_values |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_choices |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_info |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_map_value |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_param |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_results_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_results_nonull |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_set_settings |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_signing |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_signing_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_status |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::vote_voting_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::voting_from_file |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::voting_has_sign |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::voting_info |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::voting_info_id |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Epoll::DB; | ||||
| 2 | |||||
| 3 | # $Id: DB.pm 337 2010-10-05 22:43:38Z misc $ | ||||
| 4 | |||||
| 5 | 3 | 340µs | 2 | 286µ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 # spent 170µs making 1 call to Epoll::DB::BEGIN@5
# spent 116µs making 1 call to strict::import |
| 6 | 3 | 155µs | 2 | 425µ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 # spent 304µs making 1 call to Epoll::DB::BEGIN@6
# spent 121µs making 1 call to warnings::import |
| 7 | 3 | 94µs | 2 | 14.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 # spent 7.01ms making 1 call to Epoll::DB::BEGIN@7
# spent 6.98ms making 1 call to base::import |
| 8 | 3 | 6.58ms | 2 | 363ms | # 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 # spent 363ms making 1 call to Epoll::DB::BEGIN@8
# spent 83µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 3µs | our $VERSION = '1.90'; | ||
| 11 | |||||
| 12 | =head1 NAME | ||||
| 13 | |||||
| 14 | Epoll::Model::Vote - Catalyst Model | ||||
| 15 | |||||
| 16 | =head1 DESCRIPTION | ||||
| 17 | |||||
| 18 | Catalyst 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 | ||||
| 23 | 1 | 5µs | my ($class, $dbstring) = @_; | ||
| 24 | |||||
| 25 | 1 | 44µs | 1 | 275ms | 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 | |||||
| 31 | sub 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 | |||||
| 51 | sub 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 | |||||
| 69 | sub 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 | ||||
| 89 | 9 | 23µs | my ($self, $pollid) = @_; | ||
| 90 | 9 | 526µs | 18 | 61.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 | |||||
| 93 | sub 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 | ||||
| 99 | sub ballot {die "# ballot" . join(' ',caller());} | ||||
| 100 | sub vote_param { die "# vote_param" . join(' ',caller());} | ||||
| 101 | sub vote_status {die "# vote_status" . join(' ',caller());} | ||||
| 102 | sub vote_info {die "# vote_info" . join(' ',caller());} | ||||
| 103 | sub vote_set_settings {die "# old functions" . join(' ',caller());} | ||||
| 104 | sub vote_signing {die "# old functions" . join(' ',caller());} | ||||
| 105 | sub vote_voting {die "# old functions" . join(' ',caller());} | ||||
| 106 | sub voting_info {die "# old functions" . join(' ',caller());} | ||||
| 107 | sub vote_choices {die "# old functions" . join(' ',caller());} | ||||
| 108 | sub vote_add_choice {die "# old functions" . join(' ',caller());} | ||||
| 109 | sub choice_info {die "# old functions" . join(' ',caller());} | ||||
| 110 | sub delete_choice {die "# old functions" . join(' ',caller());} | ||||
| 111 | sub voting_info_id {die "# old functions" . join(' ',caller());} | ||||
| 112 | sub register_ballot {die "# old functions" . join(' ',caller());} | ||||
| 113 | sub vote_voting_count {die "# old functions" . join(' ',caller());} | ||||
| 114 | sub signing_count { vote_signing_count(@_) } | ||||
| 115 | sub vote_signing_count {die "# old functions" . join(' ',caller());} | ||||
| 116 | sub ballot_count { vote_ballot_count(@_) } | ||||
| 117 | sub vote_ballot_count {die "# old functions" . join(' ',caller());} | ||||
| 118 | sub ballot_count_nonull { vote_ballot_count_nonull(@_) } | ||||
| 119 | sub vote_ballot_count_nonull {die "# old functions" . join(' ',caller());} | ||||
| 120 | sub auth_voting {die "# old functions" . join(' ',caller());} | ||||
| 121 | sub auth_poll {die "# old functions" . join(' ',caller());} | ||||
| 122 | sub voting_has_sign {die "# old functions" . join(' ',caller());} | ||||
| 123 | sub vote_results_count {die "# old functions" . join(' ',caller());} | ||||
| 124 | sub vote_results_nonull {die "# old functions" . join(' ',caller());} | ||||
| 125 | sub list_vote_ballot {die "# old functions" . join(' ',caller());} | ||||
| 126 | sub list_vote_ballot_needvalid {die "# old functions" . join(' ',caller());} | ||||
| 127 | sub ballot_info {die "# vote_status" . join(' ',caller());} | ||||
| 128 | sub mark_ballot_invalid {die "# old functions" . join(' ',caller());} | ||||
| 129 | sub ballot_items {die "# old functions" . join(' ',caller());} | ||||
| 130 | sub vote_ballot_untrusted_values {die "# old functions" . join(' ',caller());} | ||||
| 131 | sub vote_ballot_values {die "# old functions" . join(' ',caller());} | ||||
| 132 | sub vote_map_value {die "# old functions" . join(' ',caller());} | ||||
| 133 | sub addupd_voting {die "# old functions" . join(' ',caller());} | ||||
| 134 | sub delete_voting {die "# old functions" . join(' ',caller());} | ||||
| 135 | sub voting_from_file {die "# old functions" . join(' ',caller());} | ||||
| 136 | |||||
| 137 | sub clean_old_poll_request { | ||||
| 138 | my ($self) = @_; | ||||
| 139 | $self->db->do(q{delete from poll_request where "create" < now() - '30 days'::interval}); | ||||
| 140 | } | ||||
| 141 | |||||
| 142 | sub 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 | |||||
| 155 | sub 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 | |||||
| 170 | sub create_poll { | ||||
| 171 | my ($self, @args) = @_; | ||||
| 172 | my $uid = $self->_create_poll(@args); | ||||
| 173 | $self->commit; | ||||
| 174 | $uid; | ||||
| 175 | } | ||||
| 176 | |||||
| 177 | sub _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 | |||||
| 204 | sub 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 | |||||
| 219 | sub 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 | |||||
| 242 | sub 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 | |||||
| 262 | sub 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 | |||||
| 277 | sub 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 | |||||
| 305 | Thauvin Olivier | ||||
| 306 | |||||
| 307 | =head1 LICENSE | ||||
| 308 | |||||
| 309 | This library is free software, you can redistribute it and/or modify | ||||
| 310 | it under the same terms as Perl itself or CeCILL. | ||||
| 311 | |||||
| 312 | =cut | ||||
| 313 | |||||
| 314 | 1 | 58µs | 1; |