| File | /usr/lib/perl5/vendor_perl/5.10.1/Epoll/DB/Poll.pm |
| Statements Executed | 37084 |
| Statement Execution Time | 3.31s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1794 | 3 | 1 | 205ms | 1.96s | Epoll::DB::Poll::raw_info |
| 839 | 2 | 2 | 91.6ms | 2.59s | Epoll::DB::Poll::voting |
| 842 | 7 | 3 | 78.4ms | 923ms | Epoll::DB::Poll::status |
| 897 | 15 | 6 | 50.6ms | 2.01s | Epoll::DB::Poll::info |
| 3506 | 8 | 1 | 38.4ms | 38.4ms | Epoll::DB::Poll::voteid |
| 1766 | 1 | 1 | 20.5ms | 20.5ms | Epoll::DB::Poll::_online_f |
| 852 | 15 | 5 | 19.5ms | 1.89s | Epoll::DB::Poll::uid |
| 1 | 1 | 1 | 15.6ms | 98.7ms | Epoll::DB::Poll::voting_keys |
| 9 | 1 | 1 | 4.69ms | 34.9ms | Epoll::DB::Poll::new |
| 1 | 1 | 1 | 4.45ms | 309ms | Epoll::DB::Poll::BEGIN@8 |
| 1 | 1 | 1 | 4.20ms | 12.5ms | Epoll::DB::Poll::BEGIN@10 |
| 1 | 1 | 1 | 3.95ms | 9.85ms | Epoll::DB::Poll::BEGIN@15 |
| 1 | 1 | 1 | 2.33ms | 3.26ms | Epoll::DB::Poll::BEGIN@13 |
| 1 | 1 | 2 | 2.23ms | 2.23ms | Epoll::DB::Poll::CORE:crypt (opcode) |
| 30 | 2 | 1 | 2.22ms | 35.4ms | Epoll::DB::Poll::_info |
| 1 | 1 | 1 | 1.45ms | 2.43ms | Epoll::DB::Poll::BEGIN@16 |
| 1 | 1 | 1 | 1.44ms | 2.15ms | Epoll::DB::Poll::BEGIN@12 |
| 1 | 1 | 1 | 1.41ms | 1.98ms | Epoll::DB::Poll::BEGIN@9 |
| 1 | 1 | 1 | 1.33ms | 2.03ms | Epoll::DB::Poll::BEGIN@14 |
| 1 | 1 | 1 | 236µs | 6.45ms | Epoll::DB::Poll::list_voting_no_passwd |
| 1 | 1 | 1 | 217µs | 4.80ms | Epoll::DB::Poll::voters_count |
| 9 | 1 | 1 | 155µs | 16.8ms | Epoll::DB::Poll::type |
| 9 | 1 | 2 | 101µs | 101µs | Epoll::DB::Poll::CORE:match (opcode) |
| 1 | 1 | 1 | 64µs | 6.10ms | Epoll::DB::Poll::auth_poll |
| 1 | 1 | 1 | 54µs | 66µs | Epoll::DB::Poll::BEGIN@5 |
| 1 | 1 | 1 | 38µs | 226µs | Epoll::DB::Poll::BEGIN@17 |
| 1 | 1 | 1 | 33µs | 165µs | Epoll::DB::Poll::BEGIN@11 |
| 1 | 1 | 1 | 32µs | 88µs | Epoll::DB::Poll::BEGIN@6 |
| 1 | 1 | 1 | 30µs | 588µs | Epoll::DB::Poll::BEGIN@7 |
| 1 | 1 | 1 | 20µs | 4.82ms | Epoll::DB::Poll::voting_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::_delete_ballot |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::_register_signing |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::add_choice |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::addupd_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::auth_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot_by_value |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot_count_clear |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot_count_crypt |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot_keys |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot_untrusted_ids |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot_untrusted_values |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballot_values |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::ballots_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::bdata |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::bsubmit |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::can_show_result |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::choice |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::choices |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::choices_keys |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::compute_results |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::decrypted_ballots |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::delete_ballots |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::delete_choice |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::delete_voting |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::empty_ballot_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::find_choice_key |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::gen_poll_keys |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::invalid_ballot_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::is_crypted |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::list_ballot |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::list_ballot_enc |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::list_ballot_invalid |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::list_ballot_need_dec |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::list_ballot_needvalid |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::list_ballot_valid |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::mail_voting_passwd |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::map_value |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::not_empty_ballot_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::not_signing_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::param |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::private_key |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::public_key |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::register_ballot |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::results |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::rsa |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::set_settings |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::setup |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::signing |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::signing_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::valid_ballot_count |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::value_map_to |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::voting_from_file |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::voting_from_import |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::voting_from_mail |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::voting_has_sign |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::voting_info |
| 0 | 0 | 0 | 0s | 0s | Epoll::DB::Poll::voting_info_id |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Epoll::DB::Poll; | ||||
| 2 | |||||
| 3 | # $Id: Poll.pm 319 2010-06-01 08:48:29Z nanardon $ | ||||
| 4 | |||||
| 5 | 3 | 86µs | 2 | 79µs | # spent 66µs (54+13) within Epoll::DB::Poll::BEGIN@5 which was called
# once (54µs+13µs) by Epoll::DB::BEGIN@8 at line 5 # spent 66µs making 1 call to Epoll::DB::Poll::BEGIN@5
# spent 12µs making 1 call to strict::import |
| 6 | 3 | 86µs | 2 | 144µs | # spent 88µs (32+56) within Epoll::DB::Poll::BEGIN@6 which was called
# once (32µs+56µs) by Epoll::DB::BEGIN@8 at line 6 # spent 88µs making 1 call to Epoll::DB::Poll::BEGIN@6
# spent 56µs making 1 call to warnings::import |
| 7 | 3 | 87µs | 2 | 1.15ms | # spent 588µs (30+559) within Epoll::DB::Poll::BEGIN@7 which was called
# once (30µs+559µs) by Epoll::DB::BEGIN@8 at line 7 # spent 588µs making 1 call to Epoll::DB::Poll::BEGIN@7
# spent 558µs making 1 call to base::import |
| 8 | 3 | 479µs | 2 | 309ms | # spent 309ms (4.45+305) within Epoll::DB::Poll::BEGIN@8 which was called
# once (4.45ms+305ms) by Epoll::DB::BEGIN@8 at line 8 # spent 309ms making 1 call to Epoll::DB::Poll::BEGIN@8
# spent 9µs making 1 call to UNIVERSAL::import |
| 9 | 3 | 562µs | 2 | 1.98ms | # spent 1.98ms (1.41+570µs) within Epoll::DB::Poll::BEGIN@9 which was called
# once (1.41ms+570µs) by Epoll::DB::BEGIN@8 at line 9 # spent 1.98ms making 1 call to Epoll::DB::Poll::BEGIN@9
# spent 8µs making 1 call to UNIVERSAL::import |
| 10 | 3 | 514µs | 2 | 12.5ms | # spent 12.5ms (4.20+8.34) within Epoll::DB::Poll::BEGIN@10 which was called
# once (4.20ms+8.34ms) by Epoll::DB::BEGIN@8 at line 10 # spent 12.5ms making 1 call to Epoll::DB::Poll::BEGIN@10
# spent 8µs making 1 call to UNIVERSAL::import |
| 11 | 3 | 141µs | 2 | 296µs | # spent 165µs (33+132) within Epoll::DB::Poll::BEGIN@11 which was called
# once (33µs+132µs) by Epoll::DB::BEGIN@8 at line 11 # spent 165µs making 1 call to Epoll::DB::Poll::BEGIN@11
# spent 132µs making 1 call to Exporter::import |
| 12 | 3 | 436µs | 2 | 2.23ms | # spent 2.15ms (1.44+706µs) within Epoll::DB::Poll::BEGIN@12 which was called
# once (1.44ms+706µs) by Epoll::DB::BEGIN@8 at line 12 # spent 2.15ms making 1 call to Epoll::DB::Poll::BEGIN@12
# spent 83µs making 1 call to Exporter::import |
| 13 | 3 | 315µs | 2 | 3.37ms | # spent 3.26ms (2.33+931µs) within Epoll::DB::Poll::BEGIN@13 which was called
# once (2.33ms+931µs) by Epoll::DB::BEGIN@8 at line 13 # spent 3.26ms making 1 call to Epoll::DB::Poll::BEGIN@13
# spent 104µs making 1 call to Exporter::import |
| 14 | 3 | 521µs | 2 | 2.11ms | # spent 2.03ms (1.33+701µs) within Epoll::DB::Poll::BEGIN@14 which was called
# once (1.33ms+701µs) by Epoll::DB::BEGIN@8 at line 14 # spent 2.03ms making 1 call to Epoll::DB::Poll::BEGIN@14
# spent 78µs making 1 call to Exporter::import |
| 15 | 3 | 559µs | 2 | 9.99ms | # spent 9.85ms (3.95+5.89) within Epoll::DB::Poll::BEGIN@15 which was called
# once (3.95ms+5.89ms) by Epoll::DB::BEGIN@8 at line 15 # spent 9.85ms making 1 call to Epoll::DB::Poll::BEGIN@15
# spent 140µs making 1 call to Exporter::import |
| 16 | 3 | 444µs | 2 | 2.51ms | # spent 2.43ms (1.45+983µs) within Epoll::DB::Poll::BEGIN@16 which was called
# once (1.45ms+983µs) by Epoll::DB::BEGIN@8 at line 16 # spent 2.43ms making 1 call to Epoll::DB::Poll::BEGIN@16
# spent 85µs making 1 call to Exporter::import |
| 17 | 3 | 17.1ms | 2 | 415µs | # spent 226µs (38+188) within Epoll::DB::Poll::BEGIN@17 which was called
# once (38µs+188µs) by Epoll::DB::BEGIN@8 at line 17 # spent 226µs making 1 call to Epoll::DB::Poll::BEGIN@17
# spent 188µs making 1 call to Exporter::import |
| 18 | |||||
| 19 | =head1 NAME | ||||
| 20 | |||||
| 21 | Epoll::Model::Vote - Catalyst Model | ||||
| 22 | |||||
| 23 | =head1 DESCRIPTION | ||||
| 24 | |||||
| 25 | Catalyst Model. | ||||
| 26 | |||||
| 27 | =head1 POLL PROPERTIES | ||||
| 28 | |||||
| 29 | =head2 INLINES PROPERTIES | ||||
| 30 | |||||
| 31 | =over 4 | ||||
| 32 | |||||
| 33 | =item id | ||||
| 34 | |||||
| 35 | Unique identifier | ||||
| 36 | |||||
| 37 | =item label | ||||
| 38 | |||||
| 39 | The poll label | ||||
| 40 | |||||
| 41 | =item start | ||||
| 42 | |||||
| 43 | The timestamp when poll start | ||||
| 44 | |||||
| 45 | =item end | ||||
| 46 | |||||
| 47 | The timestamp when poll stop | ||||
| 48 | |||||
| 49 | =item password | ||||
| 50 | |||||
| 51 | The poll password encrypted using crypt() | ||||
| 52 | |||||
| 53 | =item owner | ||||
| 54 | |||||
| 55 | The mail of the owner | ||||
| 56 | |||||
| 57 | =back | ||||
| 58 | |||||
| 59 | =head2 EXTENDED PROPERTIES | ||||
| 60 | |||||
| 61 | =over 4 | ||||
| 62 | |||||
| 63 | =item uid | ||||
| 64 | |||||
| 65 | The anonyme uid of the poll (to use in url) | ||||
| 66 | |||||
| 67 | =item choice_count | ||||
| 68 | |||||
| 69 | The count of possible choice in ballot | ||||
| 70 | |||||
| 71 | =item elected_choice | ||||
| 72 | |||||
| 73 | Count of select from voting list | ||||
| 74 | |||||
| 75 | =item free_choice | ||||
| 76 | |||||
| 77 | The count of free text input on ballot | ||||
| 78 | |||||
| 79 | =item description | ||||
| 80 | |||||
| 81 | The long description of the poll | ||||
| 82 | |||||
| 83 | =item procedure | ||||
| 84 | |||||
| 85 | A text about rules of the poll | ||||
| 86 | |||||
| 87 | =item private_key | ||||
| 88 | |||||
| 89 | The RSA private key of the poll (if any) | ||||
| 90 | |||||
| 91 | =item public_key | ||||
| 92 | |||||
| 93 | The RSA public key of the poll (if any) | ||||
| 94 | |||||
| 95 | =item no_mail_confirm_vote | ||||
| 96 | |||||
| 97 | Do not sent mail to voting to confirm vote | ||||
| 98 | |||||
| 99 | =item no_mail_ballot_id | ||||
| 100 | |||||
| 101 | Don't include ballot id in mail confirmation | ||||
| 102 | |||||
| 103 | =item no_ballot_id_voting | ||||
| 104 | |||||
| 105 | Do not give ballot's id to voting people on website | ||||
| 106 | |||||
| 107 | =back | ||||
| 108 | |||||
| 109 | =cut | ||||
| 110 | |||||
| 111 | # spent 34.9ms (4.69+30.2) within Epoll::DB::Poll::new which was called 9 times, avg 3.88ms/call:
# 9 times (4.69ms+30.2ms) by Epoll::DB::poll at line 90 of Epoll/DB.pm, avg 3.88ms/call | ||||
| 112 | 9 | 34µs | my ($class, $dbstring, $voteid) = @_; | ||
| 113 | |||||
| 114 | 9 | 169µs | 9 | 101µs | $voteid && $voteid =~ /^\d+$/ or return; # spent 101µs making 9 calls to Epoll::DB::Poll::CORE:match, avg 11µs/call |
| 115 | |||||
| 116 | 9 | 182µs | 9 | 12.5ms | my $poll = bless { # spent 12.5ms making 9 calls to Epoll::DB::common::_newdb, avg 1.39ms/call |
| 117 | voteid => $voteid, | ||||
| 118 | dbstring => $dbstring, | ||||
| 119 | db => Epoll::DB::common::_newdb($dbstring), | ||||
| 120 | }, $class; | ||||
| 121 | |||||
| 122 | 9 | 131µs | 9 | 16.8ms | my $type = $poll->type; # spent 16.8ms making 9 calls to Epoll::DB::Poll::type, avg 1.87ms/call |
| 123 | |||||
| 124 | 9 | 22µs | $type = ucfirst(lc($type)); | ||
| 125 | 9 | 1.80ms | eval "require Epoll::DB::Poll::Type::$type;"; | ||
| 126 | 9 | 14µs | if ($@) { | ||
| 127 | return; | ||||
| 128 | } else { | ||||
| 129 | 9 | 156µs | return bless($poll, "Epoll::DB::Poll::Type::$type"); | ||
| 130 | } | ||||
| 131 | } | ||||
| 132 | |||||
| 133 | 9 | 137µs | 9 | 16.7ms | # spent 16.8ms (155µs+16.7) within Epoll::DB::Poll::type which was called 9 times, avg 1.87ms/call:
# 9 times (155µs+16.7ms) by Epoll::DB::Poll::new at line 122, avg 1.87ms/call # spent 16.7ms making 9 calls to Epoll::DB::Poll::info, avg 1.85ms/call |
| 134 | |||||
| 135 | 3506 | 45.7ms | # spent 38.4ms within Epoll::DB::Poll::voteid which was called 3506 times, avg 11µs/call:
# 1764 times (18.6ms+0s) by Epoll::DB::Poll::raw_info at line 236, avg 11µs/call
# 842 times (9.79ms+0s) by Epoll::DB::Poll::status at line 193, avg 12µs/call
# 839 times (9.55ms+0s) by Epoll::DB::Poll::voting at line 322, avg 11µs/call
# 30 times (248µs+0s) by Epoll::DB::Poll::_info at line 220, avg 8µs/call
# 28 times (183µs+0s) by Epoll::DB::Poll::raw_info at line 247, avg 7µs/call
# once (11µs+0s) by Epoll::DB::Poll::voters_count at line 1039
# once (11µs+0s) by Epoll::DB::Poll::voting_keys at line 352
# once (10µs+0s) by Epoll::DB::Poll::list_voting_no_passwd at line 936 | ||
| 136 | |||||
| 137 | # spent 1.89s (19.5ms+1.87) within Epoll::DB::Poll::uid which was called 852 times, avg 2.22ms/call:
# 836 times (19.2ms+1.84s) by Template::Stash::XS::get at line 69 of Epoll/root/templates/admin/voters.tt, avg 2.22ms/call
# 3 times (38µs+4.03ms) by Template::Stash::XS::get at line 7 of Epoll/root/mail/voting_passwd.tt, avg 1.36ms/call
# once (18µs+4.08ms) by Template::Stash::XS::get at line 19 of Epoll/root/templates/includes/admin_menu.tt
# once (16µs+2.70ms) by Epoll::Controller::Admin::auth at line 163 of Epoll/Controller/Admin.pm
# once (17µs+2.41ms) by Template::Stash::XS::get at line 9 of Epoll/root/templates/includes/admin_menu.tt
# once (18µs+2.29ms) by Template::Stash::XS::get at line 7 of Epoll/root/templates/includes/admin_menu.tt
# once (17µs+2.28ms) by Template::Stash::XS::get at line 11 of Epoll/root/templates/includes/admin_menu.tt
# once (16µs+2.25ms) by Epoll::Controller::Admin::auth at line 164 of Epoll/Controller/Admin.pm
# once (20µs+2.22ms) by Template::Stash::XS::get at line 24 of Epoll/root/templates/admin/voters.tt
# once (18µs+2.11ms) by Template::Stash::XS::get at line 5 of Epoll/root/templates/includes/admin_menu.tt
# once (31µs+1.97ms) by Epoll::Controller::Admin::auth at line 153 of Epoll/Controller/Admin.pm
# once (68µs+1.91ms) by Template::Stash::XS::get at line 9 of Epoll/root/templates/admin/voters.tt
# once (18µs+1.95ms) by Template::Stash::XS::get at line 33 of Epoll/root/templates/admin/voters.tt
# once (16µs+1.95ms) by Epoll::Controller::Admin::auth at line 165 of Epoll/Controller/Admin.pm
# once (9µs+797µs) by Template::Stash::XS::get at line 30 of Epoll/root/templates/includes/header.tt | ||||
| 138 | 852 | 3.56ms | my ($self) = @_; | ||
| 139 | # UID will come only with epoll 2.0, if no uid, using key | ||||
| 140 | 852 | 16.0ms | 852 | 1.87s | return $self->info('uid') || $self->voteid; # spent 1.87s making 852 calls to Epoll::DB::Poll::info, avg 2.20ms/call |
| 141 | } | ||||
| 142 | |||||
| 143 | sub setup { | ||||
| 144 | my ($self) = @_; | ||||
| 145 | $self->param( | ||||
| 146 | free_choice => 0, | ||||
| 147 | choice_count => 1, | ||||
| 148 | uid => Epoll::DB::common::random_string(), | ||||
| 149 | ); | ||||
| 150 | } | ||||
| 151 | |||||
| 152 | 1766 | 30.2ms | # spent 20.5ms within Epoll::DB::Poll::_online_f which was called 1766 times, avg 12µs/call:
# 1766 times (20.5ms+0s) by Epoll::DB::Poll::raw_info at line 230, avg 12µs/call | ||
| 153 | |||||
| 154 | sub param { | ||||
| 155 | my ($self, %attr) = @_; | ||||
| 156 | |||||
| 157 | keys %attr or return; | ||||
| 158 | my @online_f = _online_f(); | ||||
| 159 | |||||
| 160 | $self->db->do(q{set DATESTYLE to 'DMY'}); | ||||
| 161 | if (grep { exists($attr{$_}) } @online_f) { | ||||
| 162 | my $sth = $self->db->prepare_cached( | ||||
| 163 | q{update poll set } . | ||||
| 164 | join(',', map { qq("$_" = ?) } grep { exists $attr{$_} } @online_f) . | ||||
| 165 | q{ where id = ?} | ||||
| 166 | ); | ||||
| 167 | $sth->execute((map { $attr{$_} } grep { exists $attr{$_} } @online_f), $self->voteid) | ||||
| 168 | or do { | ||||
| 169 | $self->rollback; | ||||
| 170 | return; | ||||
| 171 | }; | ||||
| 172 | } | ||||
| 173 | |||||
| 174 | # vote settings in settings table | ||||
| 175 | foreach my $var (keys %attr) { | ||||
| 176 | grep { $var eq $_ } @online_f and next; | ||||
| 177 | $self->set_settings($var, $attr{$var}); | ||||
| 178 | } | ||||
| 179 | 1 | ||||
| 180 | } | ||||
| 181 | |||||
| 182 | # spent 923ms (78.4+845) within Epoll::DB::Poll::status which was called 842 times, avg 1.10ms/call:
# 836 times (77.8ms+837ms) by Template::Stash::XS::get at line 73 of Epoll/root/templates/admin/voters.tt, avg 1.09ms/call
# once (152µs+2.59ms) by Epoll::Controller::Admin::voters at line 197 of Epoll/Controller/Admin.pm
# once (125µs+1.17ms) by Template::Stash::XS::get at line 17 of Epoll/root/templates/includes/admin_menu.tt
# once (81µs+1.10ms) by Template::Stash::XS::get at line 42 of Epoll/root/templates/admin/voters.tt
# once (80µs+1.03ms) by Template::Stash::XS::get at line 12 of Epoll/root/templates/includes/admin_menu.tt
# once (73µs+966µs) by Template::Stash::XS::get at line 8 of Epoll/root/templates/includes/admin_menu.tt
# once (72µs+814µs) by Template::Stash::XS::get at line 20 of Epoll/root/templates/includes/admin_menu.tt | ||||
| 183 | 842 | 2.31ms | my ($self) = @_; | ||
| 184 | |||||
| 185 | 842 | 30.5ms | 2526 | 283ms | my $sth = $self->db->prepare_cached( # spent 114ms making 842 calls to Epoll::DB::common::db, avg 135µs/call
# spent 94.3ms making 842 calls to DBI::db::prepare_cached, avg 112µs/call
# spent 75.4ms making 842 calls to DBD::_::db::prepare_cached, avg 90µs/call |
| 186 | q{ | ||||
| 187 | select (start > now() or start is null) as before, | ||||
| 188 | "end" < now() as after | ||||
| 189 | from poll | ||||
| 190 | where id = ? | ||||
| 191 | } | ||||
| 192 | ); | ||||
| 193 | 842 | 537ms | 1684 | 525ms | $sth->execute($self->voteid); # spent 516ms making 842 calls to DBI::st::execute, avg 612µs/call
# spent 9.79ms making 842 calls to Epoll::DB::Poll::voteid, avg 12µs/call |
| 194 | 842 | 108ms | 2526 | 146ms | my $res = $sth->fetchrow_hashref; # spent 95.2ms making 842 calls to DBI::st::fetchrow_hashref, avg 113µs/call
# spent 27.0ms making 842 calls to DBI::st::fetch, avg 32µs/call
# spent 23.9ms making 842 calls to DBI::common::FETCH, avg 28µs/call |
| 195 | 842 | 25.0ms | 842 | 16.4ms | $sth->finish; # spent 16.4ms making 842 calls to DBI::st::finish, avg 19µs/call |
| 196 | 842 | 2.02ms | $res or return; | ||
| 197 | 842 | 14.7ms | if ($res->{before}) { | ||
| 198 | return 'BEFORE'; | ||||
| 199 | } elsif ($res->{after}) { | ||||
| 200 | return 'AFTER'; | ||||
| 201 | } else { | ||||
| 202 | return 'RUNNING'; | ||||
| 203 | } | ||||
| 204 | } | ||||
| 205 | |||||
| 206 | sub _info { | ||||
| 207 | 30 | 50µs | my ($self) = @_; | ||
| 208 | |||||
| 209 | 30 | 948µs | 90 | 7.83ms | my $sth = $self->db->prepare_cached( # spent 2.85ms making 30 calls to Epoll::DB::common::db, avg 95µs/call
# spent 2.81ms making 30 calls to DBI::db::prepare_cached, avg 94µs/call
# spent 2.17ms making 30 calls to DBD::_::db::prepare_cached, avg 72µs/call |
| 210 | q{ | ||||
| 211 | select *, | ||||
| 212 | to_char("start", 'DD/MM/YYYY') as dstart, | ||||
| 213 | to_char("start", 'HH24:MI:SS') as hstart, | ||||
| 214 | to_char("end", 'DD/MM/YYYY') as dend, | ||||
| 215 | to_char("end", 'HH24:MI:SS') as hend | ||||
| 216 | from poll where id = ? | ||||
| 217 | } | ||||
| 218 | ); | ||||
| 219 | |||||
| 220 | 30 | 22.5ms | 60 | 22.2ms | $sth->execute($self->voteid); # spent 21.9ms making 30 calls to DBI::st::execute, avg 731µs/call
# spent 248µs making 30 calls to Epoll::DB::Poll::voteid, avg 8µs/call |
| 221 | 30 | 5.27ms | 90 | 8.10ms | my $res = $sth->fetchrow_hashref; # spent 4.86ms making 30 calls to DBI::st::fetchrow_hashref, avg 162µs/call
# spent 1.65ms making 30 calls to DBI::common::FETCH, avg 55µs/call
# spent 1.59ms making 30 calls to DBI::st::fetch, avg 53µs/call |
| 222 | 30 | 666µs | 30 | 455µs | $sth->finish; # spent 455µs making 30 calls to DBI::st::finish, avg 15µs/call |
| 223 | 30 | 356µs | $res | ||
| 224 | } | ||||
| 225 | |||||
| 226 | # spent 1.96s (205ms+1.76) within Epoll::DB::Poll::raw_info which was called 1794 times, avg 1.09ms/call:
# 897 times (106ms+866ms) by Epoll::DB::Poll::info at line 259, avg 1.08ms/call
# 869 times (95.0ms+821ms) by Epoll::DB::Poll::info at line 265, avg 1.05ms/call
# 28 times (3.70ms+68.1ms) by Epoll::DB::Poll::info at line 264, avg 2.56ms/call | ||||
| 227 | 1794 | 5.24ms | my ($self, $var) = @_; | ||
| 228 | |||||
| 229 | 1794 | 3.36ms | if ($var) { | ||
| 230 | 1766 | 27.5ms | 1768 | 22.1ms | if (grep { $var eq $_ } (_online_f(), qw(dstart hstart dend hend))) { # spent 20.5ms making 1766 calls to Epoll::DB::Poll::_online_f, avg 12µs/call
# spent 1.54ms making 2 calls to Epoll::DB::Poll::_info, avg 768µs/call |
| 231 | return ( $self->_info || {} )->{$var}; | ||||
| 232 | } else { | ||||
| 233 | 1764 | 65.0ms | 5292 | 566ms | my $sth = $self->db->prepare_cached( # spent 238ms making 1764 calls to Epoll::DB::common::db, avg 135µs/call
# spent 183ms making 1764 calls to DBI::db::prepare_cached, avg 104µs/call
# spent 145ms making 1764 calls to DBD::_::db::prepare_cached, avg 82µs/call |
| 234 | q{select val from settings where poll = ? and var = ?} | ||||
| 235 | ); | ||||
| 236 | 1764 | 1.05s | 3528 | 1.03s | $sth->execute($self->voteid, $var); # spent 1.01s making 1764 calls to DBI::st::execute, avg 573µs/call
# spent 18.6ms making 1764 calls to Epoll::DB::Poll::voteid, avg 11µs/call |
| 237 | 1764 | 203ms | 5292 | 263ms | my $res = $sth->fetchrow_hashref; # spent 181ms making 1764 calls to DBI::st::fetchrow_hashref, avg 102µs/call
# spent 42.2ms making 1764 calls to DBI::st::fetch, avg 24µs/call
# spent 40.6ms making 1764 calls to DBI::common::FETCH, avg 23µs/call |
| 238 | 1764 | 55.9ms | 1764 | 35.4ms | $sth->finish; # spent 35.4ms making 1764 calls to DBI::st::finish, avg 20µs/call |
| 239 | 1764 | 33.1ms | return $res->{val} | ||
| 240 | } | ||||
| 241 | } | ||||
| 242 | |||||
| 243 | 28 | 226µs | 28 | 33.9ms | if (my $res = $self->_info) { # spent 33.9ms making 28 calls to Epoll::DB::Poll::_info, avg 1.21ms/call |
| 244 | 28 | 904µs | 84 | 7.03ms | my $get = $self->db->prepare_cached( # spent 3.00ms making 28 calls to Epoll::DB::common::db, avg 107µs/call
# spent 2.23ms making 28 calls to DBI::db::prepare_cached, avg 80µs/call
# spent 1.81ms making 28 calls to DBD::_::db::prepare_cached, avg 65µs/call |
| 245 | q{select var, val from settings where poll = ?} | ||||
| 246 | ); | ||||
| 247 | 28 | 21.2ms | 56 | 20.9ms | $get->execute($self->voteid); # spent 20.7ms making 28 calls to DBI::st::execute, avg 739µs/call
# spent 183µs making 28 calls to Epoll::DB::Poll::voteid, avg 7µs/call |
| 248 | 28 | 10.1ms | 336 | 12.2ms | while (my $set = $get->fetchrow_hashref) { # spent 8.16ms making 112 calls to DBI::st::fetchrow_hashref, avg 73µs/call
# spent 2.04ms making 112 calls to DBI::common::FETCH, avg 18µs/call
# spent 2.00ms making 112 calls to DBI::st::fetch, avg 18µs/call |
| 249 | $res->{$set->{var}} = $set->{val}; | ||||
| 250 | } | ||||
| 251 | 28 | 334µs | return $res | ||
| 252 | } | ||||
| 253 | return; | ||||
| 254 | } | ||||
| 255 | |||||
| 256 | # spent 2.01s (50.6ms+1.96) within Epoll::DB::Poll::info which was called 897 times, avg 2.24ms/call:
# 852 times (46.9ms+1.83s) by Epoll::DB::Poll::uid at line 140, avg 2.20ms/call
# 9 times (1.51ms+15.1ms) by Epoll::DB::Poll::type at line 133, avg 1.85ms/call
# 6 times (374µs+21.2ms) by Template::Stash::XS::get at line 12 of Epoll/root/mail/voting_passwd.tt, avg 3.59ms/call
# 6 times (352µs+20.1ms) by Template::Stash::XS::get at line 13 of Epoll/root/mail/voting_passwd.tt, avg 3.41ms/call
# 6 times (346µs+16.1ms) by Template::Stash::XS::get at line 14 of Epoll/root/mail/voting_passwd.tt, avg 2.74ms/call
# 3 times (282µs+8.56ms) by Epoll::Controller::Admin::voters at line 210 of Epoll/Controller/Admin.pm, avg 2.95ms/call
# 3 times (179µs+8.28ms) by Template::Stash::XS::get at line 4 of Epoll/root/mail/voting_passwd.tt, avg 2.82ms/call
# 3 times (186µs+5.41ms) by Template::Stash::XS::get at line 23 of Epoll/root/mail/voting_passwd.tt, avg 1.86ms/call
# 3 times (96µs+5.22ms) by Template::Stash::XS::get at line 27 of Epoll/root/mail/voting_passwd.tt, avg 1.77ms/call
# once (77µs+15.2ms) by Epoll::Controller::Admin::voters at line 190 of Epoll/Controller/Admin.pm
# once (40µs+5.64ms) by Epoll::Controller::Admin::voters at line 228 of Epoll/Controller/Admin.pm
# once (62µs+4.72ms) by Template::Stash::XS::get at line 12 of Epoll/root/templates/includes/admin_menu.tt
# once (64µs+4.10ms) by Template::Stash::XS::get at line 39 of Epoll/root/templates/admin/voters.tt
# once (59µs+3.74ms) by Epoll::DB::Poll::auth_poll at line 550
# once (22µs+1.10ms) by Template::Stash::XS::get at line 45 of Epoll/root/templates/includes/header.tt | ||||
| 257 | 897 | 3.04ms | my ($self, $var) = @_; | ||
| 258 | |||||
| 259 | 897 | 16.2ms | 897 | 972ms | my $default = { # spent 972ms making 897 calls to Epoll::DB::Poll::raw_info, avg 1.08ms/call |
| 260 | free_choice => 0, # avoid undef in some case | ||||
| 261 | elected_count => $self->raw_info('choice_count'), | ||||
| 262 | }; | ||||
| 263 | |||||
| 264 | 897 | 2.31ms | 28 | 71.8ms | if ($var) { # spent 71.8ms making 28 calls to Epoll::DB::Poll::raw_info, avg 2.56ms/call |
| 265 | 869 | 13.1ms | 869 | 916ms | my $val = $self->raw_info($var); # spent 916ms making 869 calls to Epoll::DB::Poll::raw_info, avg 1.05ms/call |
| 266 | 869 | 11.8ms | return defined($val) | ||
| 267 | ? $val | ||||
| 268 | : $default->{$var}; | ||||
| 269 | } elsif (my $res = $self->raw_info) { | ||||
| 270 | 28 | 364µs | foreach (keys %$default) { | ||
| 271 | 56 | 389µs | $res->{$_} = $default->{$_} if (!defined($res->{$_})); | ||
| 272 | } | ||||
| 273 | 28 | 313µs | return $res | ||
| 274 | } | ||||
| 275 | return; | ||||
| 276 | } | ||||
| 277 | |||||
| 278 | sub set_settings { | ||||
| 279 | my ($self, $var, $val) = @_; | ||||
| 280 | |||||
| 281 | $val = undef if(defined($val) && $val eq ''); | ||||
| 282 | my $upd = $self->db->prepare_cached( | ||||
| 283 | q{update settings set val = ? where poll = ? and var = ?} | ||||
| 284 | ); | ||||
| 285 | |||||
| 286 | if ($upd->execute($val, $self->voteid, $var) == 0) { | ||||
| 287 | my $add = $self->db->prepare_cached( | ||||
| 288 | q{insert into settings (poll, var, val) values (?,?,?)} | ||||
| 289 | ); | ||||
| 290 | |||||
| 291 | $add->execute($self->voteid, $var, $val); | ||||
| 292 | } | ||||
| 293 | } | ||||
| 294 | |||||
| 295 | sub signing { | ||||
| 296 | my ($self) = @_; | ||||
| 297 | |||||
| 298 | my $sth = $self->db->prepare_cached( | ||||
| 299 | q{ | ||||
| 300 | select *, voting.key as vkey from voting left join signing | ||||
| 301 | on signing.key = voting.key | ||||
| 302 | where poll = ? order by voting.mail | ||||
| 303 | } | ||||
| 304 | ); | ||||
| 305 | $sth->execute($self->voteid); | ||||
| 306 | my @people; | ||||
| 307 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 308 | push(@people, $res); | ||||
| 309 | } | ||||
| 310 | @people | ||||
| 311 | } | ||||
| 312 | |||||
| 313 | # spent 2.59s (91.6ms+2.50) within Epoll::DB::Poll::voting which was called 839 times, avg 3.09ms/call:
# 836 times (91.1ms+2.48s) by Template::Stash::XS::get at line 51 of Epoll/root/templates/admin/voters.tt, avg 3.07ms/call
# 3 times (570µs+22.2ms) by Epoll::Controller::Admin::voters at line 208 of Epoll/Controller/Admin.pm, avg 7.58ms/call | ||||
| 314 | 839 | 3.12ms | my ($self, $votingkey) = @_; | ||
| 315 | |||||
| 316 | 839 | 32.4ms | 2517 | 300ms | my $sth = $self->db->prepare_cached( # spent 128ms making 839 calls to Epoll::DB::common::db, avg 153µs/call
# spent 95.1ms making 839 calls to DBI::db::prepare_cached, avg 113µs/call
# spent 77.2ms making 839 calls to DBD::_::db::prepare_cached, avg 92µs/call |
| 317 | q{ | ||||
| 318 | select key from voting where poll = ? and key = ? | ||||
| 319 | } | ||||
| 320 | ); | ||||
| 321 | |||||
| 322 | 839 | 616ms | 1678 | 602ms | $sth->execute($self->voteid, $votingkey); # spent 592ms making 839 calls to DBI::st::execute, avg 706µs/call
# spent 9.55ms making 839 calls to Epoll::DB::Poll::voteid, avg 11µs/call |
| 323 | 839 | 101ms | 2517 | 130ms | my $res = $sth->fetchrow_hashref; # spent 88.9ms making 839 calls to DBI::st::fetchrow_hashref, avg 106µs/call
# spent 20.8ms making 839 calls to DBI::common::FETCH, avg 25µs/call
# spent 19.8ms making 839 calls to DBI::st::fetch, avg 24µs/call |
| 324 | 839 | 26.0ms | 839 | 17.5ms | $sth->finish; # spent 17.5ms making 839 calls to DBI::st::finish, avg 21µs/call |
| 325 | 839 | 24.6ms | 839 | 1.57s | return $res ? Epoll::DB::Voting->new($self->{dbstring}, $votingkey) : undef; # spent 1.57s making 839 calls to Epoll::DB::Voting::new, avg 1.87ms/call |
| 326 | } | ||||
| 327 | |||||
| 328 | sub voting_from_mail { | ||||
| 329 | my ($self, $mail) = @_; | ||||
| 330 | |||||
| 331 | my $sth = $self->db->prepare_cached( | ||||
| 332 | q{ | ||||
| 333 | select key from voting where poll = ? and mail = ? | ||||
| 334 | } | ||||
| 335 | ); | ||||
| 336 | |||||
| 337 | $sth->execute($self->voteid, $mail); | ||||
| 338 | my $res = $sth->fetchrow_hashref; | ||||
| 339 | $sth->finish; | ||||
| 340 | return $res ? Epoll::DB::Voting->new($self->{dbstring}, $res->{key}) : undef; | ||||
| 341 | } | ||||
| 342 | |||||
| 343 | # spent 98.7ms (15.6+83.1) within Epoll::DB::Poll::voting_keys which was called
# once (15.6ms+83.1ms) by Template::Stash::XS::get at line 86 of Epoll/root/templates/admin/voters.tt | ||||
| 344 | 1 | 3µs | my ($self) = @_; | ||
| 345 | |||||
| 346 | 1 | 93µs | 3 | 708µs | my $sth = $self->db->prepare_cached( # spent 305µs making 1 call to DBI::db::prepare_cached
# spent 284µs making 1 call to DBD::_::db::prepare_cached
# spent 119µs making 1 call to Epoll::DB::common::db |
| 347 | q{ | ||||
| 348 | select key from voting | ||||
| 349 | where poll = ? order by voting.mail | ||||
| 350 | } | ||||
| 351 | ); | ||||
| 352 | 1 | 10.1ms | 2 | 10.1ms | $sth->execute($self->voteid); # spent 10.1ms making 1 call to DBI::st::execute
# spent 11µs making 1 call to Epoll::DB::Poll::voteid |
| 353 | 1 | 2µs | my @people; | ||
| 354 | 1 | 87.9ms | 2511 | 111ms | while (my $res = $sth->fetchrow_hashref) { # spent 72.6ms making 837 calls to DBI::st::fetchrow_hashref, avg 87µs/call
# spent 21.6ms making 837 calls to DBI::st::fetch, avg 26µs/call
# spent 16.6ms making 837 calls to DBI::common::FETCH, avg 20µs/call |
| 355 | push(@people, $res->{key}); | ||||
| 356 | } | ||||
| 357 | @people | ||||
| 358 | 1 | 165µs | } | ||
| 359 | |||||
| 360 | sub voting_info { | ||||
| 361 | my ($self) = @_; | ||||
| 362 | |||||
| 363 | my $sth = $self->db->prepare_cached( | ||||
| 364 | q{ | ||||
| 365 | select *, voting.key as vkey from voting left join signing | ||||
| 366 | on signing.key = voting.key | ||||
| 367 | where voting.key = ? | ||||
| 368 | } | ||||
| 369 | ); | ||||
| 370 | $sth->execute($self->voteid); | ||||
| 371 | |||||
| 372 | my $res = $sth->fetchrow_hashref; | ||||
| 373 | $sth->finish; | ||||
| 374 | $res | ||||
| 375 | } | ||||
| 376 | |||||
| 377 | sub choice { | ||||
| 378 | my ($self, $chid) = @_; | ||||
| 379 | |||||
| 380 | my $sth = $self->db->prepare_cached( | ||||
| 381 | q{ | ||||
| 382 | select key from choice where poll = ? and key = ? | ||||
| 383 | } | ||||
| 384 | ); | ||||
| 385 | $sth->execute($self->voteid, $chid); | ||||
| 386 | my $res = $sth->fetchrow_hashref; | ||||
| 387 | $sth->finish; | ||||
| 388 | return $res ? Epoll::DB::Choice->new($self->{dbstring}, $chid) : undef; | ||||
| 389 | } | ||||
| 390 | |||||
| 391 | sub choices_keys { | ||||
| 392 | my ($self) = @_; | ||||
| 393 | |||||
| 394 | my $sth = $self->db->prepare_cached( | ||||
| 395 | q{ | ||||
| 396 | select key from choice where poll = ? | ||||
| 397 | order by label | ||||
| 398 | } | ||||
| 399 | ); | ||||
| 400 | $sth->execute($self->voteid); | ||||
| 401 | my @ch; | ||||
| 402 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 403 | push(@ch, $res->{key}); | ||||
| 404 | } | ||||
| 405 | @ch | ||||
| 406 | } | ||||
| 407 | |||||
| 408 | # TODO: replaced, to kill | ||||
| 409 | sub choices { | ||||
| 410 | my ($self) = @_; | ||||
| 411 | |||||
| 412 | my $sth = $self->db->prepare_cached( | ||||
| 413 | q{ | ||||
| 414 | select key from choice where poll = ? | ||||
| 415 | order by label | ||||
| 416 | } | ||||
| 417 | ); | ||||
| 418 | $sth->execute($self->voteid); | ||||
| 419 | my @ch; | ||||
| 420 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 421 | push(@ch, $res->{key}); | ||||
| 422 | } | ||||
| 423 | @ch | ||||
| 424 | } | ||||
| 425 | |||||
| 426 | sub add_choice { | ||||
| 427 | my ($self, $label) = @_; | ||||
| 428 | |||||
| 429 | my $sth = $self->db->prepare_cached( | ||||
| 430 | q{insert into choice (poll, label) values (?,?)} | ||||
| 431 | ); | ||||
| 432 | |||||
| 433 | $sth->execute($self->voteid, $label) or do { | ||||
| 434 | $self->rollback; | ||||
| 435 | return; | ||||
| 436 | }; | ||||
| 437 | |||||
| 438 | 1 | ||||
| 439 | } | ||||
| 440 | |||||
| 441 | sub delete_choice { | ||||
| 442 | my ($self, $chid) = @_; | ||||
| 443 | |||||
| 444 | my $sth = $self->db->prepare_cached( | ||||
| 445 | q{delete from choice where key = ?} | ||||
| 446 | ); | ||||
| 447 | |||||
| 448 | $sth->execute($chid); | ||||
| 449 | } | ||||
| 450 | |||||
| 451 | sub _register_signing { | ||||
| 452 | my ($self, $mail, $referal) = @_; | ||||
| 453 | |||||
| 454 | my $vinfo = $self->voting_info_id($mail) or return; | ||||
| 455 | |||||
| 456 | my $sth = $self->db->prepare_cached( | ||||
| 457 | q{ | ||||
| 458 | insert into signing (key, referal) values (?,?) | ||||
| 459 | } | ||||
| 460 | ); | ||||
| 461 | $sth->execute($vinfo->{key}, $referal) or do { | ||||
| 462 | $self->rollback; | ||||
| 463 | return; | ||||
| 464 | }; | ||||
| 465 | |||||
| 466 | 1; | ||||
| 467 | } | ||||
| 468 | |||||
| 469 | sub find_choice_key { | ||||
| 470 | my ($self, $value) = @_; | ||||
| 471 | |||||
| 472 | my $sth = $self->db->prepare_cached( | ||||
| 473 | q{select key from choice where lower(label) = ? and poll = ?} | ||||
| 474 | ); | ||||
| 475 | $sth->execute(lc($value), $self->voteid); | ||||
| 476 | my $res = $sth->fetchrow_hashref; | ||||
| 477 | $sth->finish; | ||||
| 478 | $res->{key} | ||||
| 479 | } | ||||
| 480 | |||||
| 481 | sub decrypted_ballots { | ||||
| 482 | my ($self, $password) = @_; | ||||
| 483 | my $privkey; | ||||
| 484 | if ($self->is_crypted) { | ||||
| 485 | $privkey = $self->private_key($password) or return; | ||||
| 486 | } | ||||
| 487 | my $fetch_data = $self->db->prepare_cached( | ||||
| 488 | q{select * from ballot_enc where decrypted = false and poll = ? | ||||
| 489 | order by id} | ||||
| 490 | ); | ||||
| 491 | $fetch_data->execute($self->voteid); | ||||
| 492 | while (my $res = $fetch_data->fetchrow_hashref) { | ||||
| 493 | my $bdata = $self->bdata; | ||||
| 494 | $bdata->decrypt_data($res->{id}, $res->{data}, $res->{enckey}, $privkey) | ||||
| 495 | and return; | ||||
| 496 | } | ||||
| 497 | 1 | ||||
| 498 | } | ||||
| 499 | |||||
| 500 | sub register_ballot { | ||||
| 501 | my ($self, $vmail, $choice, $referal) = @_; | ||||
| 502 | # TODO: warn, deprecated | ||||
| 503 | |||||
| 504 | my $bdata = $self->bsubmit; | ||||
| 505 | if (!$choice) { | ||||
| 506 | } elsif (ref $choice eq 'ARRAY') { | ||||
| 507 | foreach (@{ $choice || []}) { | ||||
| 508 | $bdata->add_item($_, 1); | ||||
| 509 | } | ||||
| 510 | } else { | ||||
| 511 | foreach (keys %{ $choice || {}}) { | ||||
| 512 | $bdata->add_item($_, $choice->{$_}); | ||||
| 513 | } | ||||
| 514 | } | ||||
| 515 | $bdata->set_voter($vmail, $referal); | ||||
| 516 | return $bdata->submit($vmail, $referal); | ||||
| 517 | } | ||||
| 518 | |||||
| 519 | sub is_crypted { | ||||
| 520 | my ($self) = @_; | ||||
| 521 | return $self->info->{public_key} ? 1 : 0; | ||||
| 522 | } | ||||
| 523 | |||||
| 524 | sub voting_info_id { | ||||
| 525 | my ($self, $mail) = @_; | ||||
| 526 | |||||
| 527 | my $sth = $self->db->prepare_cached( | ||||
| 528 | q{ | ||||
| 529 | select * from voting where mail = ? and poll = ? | ||||
| 530 | } | ||||
| 531 | ); | ||||
| 532 | $sth->execute($mail, $self->voteid); | ||||
| 533 | my $res = $sth->fetchrow_hashref(); | ||||
| 534 | $sth->finish; | ||||
| 535 | $res | ||||
| 536 | } | ||||
| 537 | |||||
| 538 | sub auth_voting { | ||||
| 539 | my ($self, $mail, $password) = @_; | ||||
| 540 | if (my $voter = $self->voting_from_mail($mail)) { | ||||
| 541 | return $voter->auth($password); | ||||
| 542 | } else { | ||||
| 543 | return; | ||||
| 544 | } | ||||
| 545 | } | ||||
| 546 | |||||
| 547 | # spent 6.10ms (64µs+6.03) within Epoll::DB::Poll::auth_poll which was called
# once (64µs+6.03ms) by Epoll::Controller::Admin::auth at line 156 of Epoll/Controller/Admin.pm | ||||
| 548 | 1 | 3µs | my ($self, $passwd) = @_; | ||
| 549 | |||||
| 550 | 1 | 8µs | 1 | 3.80ms | my $vinfo = $self->info or return; # spent 3.80ms making 1 call to Epoll::DB::Poll::info |
| 551 | |||||
| 552 | 1 | 2µs | $vinfo->{password} or return; | ||
| 553 | 1 | 1µs | $passwd or return; | ||
| 554 | 1 | 2.28ms | 1 | 2.23ms | if (crypt($passwd, $vinfo->{password} || '') eq $vinfo->{password}) { # spent 2.23ms making 1 call to Epoll::DB::Poll::CORE:crypt |
| 555 | return 1; | ||||
| 556 | } else { | ||||
| 557 | return 0; | ||||
| 558 | } | ||||
| 559 | } | ||||
| 560 | |||||
| 561 | sub voting_has_sign { | ||||
| 562 | my ($self, $user) = @_; | ||||
| 563 | $self->voting_from_mail($user)->has_sign; | ||||
| 564 | } | ||||
| 565 | |||||
| 566 | # Requete de decompte des voix: | ||||
| 567 | |||||
| 568 | sub can_show_result { | ||||
| 569 | my ($self) = @_; | ||||
| 570 | |||||
| 571 | # If ballot are encrypted, no | ||||
| 572 | if ($self->list_ballot_need_dec) { | ||||
| 573 | return; | ||||
| 574 | } | ||||
| 575 | |||||
| 576 | return 1; | ||||
| 577 | } | ||||
| 578 | |||||
| 579 | sub bdata { | ||||
| 580 | my ($self) = @_; | ||||
| 581 | Epoll::DB::Poll::Bdata->new($self->{dbstring}, $self); | ||||
| 582 | } | ||||
| 583 | |||||
| 584 | sub bsubmit { | ||||
| 585 | my ($self) = @_; | ||||
| 586 | Epoll::DB::Poll::BSubmit->new($self->{dbstring}, $self); | ||||
| 587 | } | ||||
| 588 | |||||
| 589 | sub ballot { | ||||
| 590 | my ($self, $id) = @_; | ||||
| 591 | |||||
| 592 | my $sth = $self->db->prepare_cached( | ||||
| 593 | q{ | ||||
| 594 | select id from ballot where poll = ? and id = ? | ||||
| 595 | } | ||||
| 596 | ); | ||||
| 597 | |||||
| 598 | $sth->execute($self->voteid, $id); | ||||
| 599 | my $res = $sth->fetchrow_hashref; | ||||
| 600 | $sth->finish; | ||||
| 601 | return $res ? Epoll::DB::Ballot->new($self->{dbstring}, $id) : undef; | ||||
| 602 | } | ||||
| 603 | |||||
| 604 | # TODO kill this: | ||||
| 605 | sub list_ballot { | ||||
| 606 | ballot_keys(@_); | ||||
| 607 | } | ||||
| 608 | |||||
| 609 | sub ballot_keys { | ||||
| 610 | my ($self) = @_; | ||||
| 611 | |||||
| 612 | my $sth = $self->db->prepare_cached( | ||||
| 613 | q{ | ||||
| 614 | select id from ballot where poll = ? | ||||
| 615 | order by id | ||||
| 616 | } | ||||
| 617 | ); | ||||
| 618 | $sth->execute($self->voteid); | ||||
| 619 | my @ids; | ||||
| 620 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 621 | push(@ids, $res->{id}); | ||||
| 622 | } | ||||
| 623 | @ids | ||||
| 624 | } | ||||
| 625 | |||||
| 626 | sub list_ballot_enc { | ||||
| 627 | my ($self) = @_; | ||||
| 628 | |||||
| 629 | my $sth = $self->db->prepare_cached( | ||||
| 630 | q{ | ||||
| 631 | select id from ballot_enc where poll = ? | ||||
| 632 | order by id | ||||
| 633 | } | ||||
| 634 | ); | ||||
| 635 | $sth->execute($self->voteid); | ||||
| 636 | my @ids; | ||||
| 637 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 638 | push(@ids, $res->{id}); | ||||
| 639 | } | ||||
| 640 | @ids | ||||
| 641 | } | ||||
| 642 | |||||
| 643 | sub list_ballot_need_dec { | ||||
| 644 | my ($self) = @_; | ||||
| 645 | |||||
| 646 | my $sth = $self->db->prepare_cached( | ||||
| 647 | q{ | ||||
| 648 | select id from ballot_enc where poll = ? and decrypted = 'false' | ||||
| 649 | order by id | ||||
| 650 | } | ||||
| 651 | ); | ||||
| 652 | $sth->execute($self->voteid); | ||||
| 653 | my @ids; | ||||
| 654 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 655 | push(@ids, $res->{id}); | ||||
| 656 | } | ||||
| 657 | @ids | ||||
| 658 | } | ||||
| 659 | |||||
| 660 | sub list_ballot_needvalid { | ||||
| 661 | my ($self) = @_; | ||||
| 662 | |||||
| 663 | my $sth = $self->db->prepare_cached( | ||||
| 664 | q{ | ||||
| 665 | select id from ballot where poll = ? | ||||
| 666 | and invalid is null order by id | ||||
| 667 | } | ||||
| 668 | ); | ||||
| 669 | $sth->execute($self->voteid); | ||||
| 670 | my @ids; | ||||
| 671 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 672 | push(@ids, $res->{id}); | ||||
| 673 | } | ||||
| 674 | @ids | ||||
| 675 | } | ||||
| 676 | |||||
| 677 | sub list_ballot_valid { | ||||
| 678 | my ($self) = @_; | ||||
| 679 | |||||
| 680 | my $sth = $self->db->prepare_cached( | ||||
| 681 | q{ | ||||
| 682 | select id from ballot where poll = ? | ||||
| 683 | and invalid = false order by id | ||||
| 684 | } | ||||
| 685 | ); | ||||
| 686 | $sth->execute($self->voteid); | ||||
| 687 | my @ids; | ||||
| 688 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 689 | push(@ids, $res->{id}); | ||||
| 690 | } | ||||
| 691 | @ids | ||||
| 692 | } | ||||
| 693 | |||||
| 694 | sub list_ballot_invalid { | ||||
| 695 | my ($self) = @_; | ||||
| 696 | |||||
| 697 | my $sth = $self->db->prepare_cached( | ||||
| 698 | q{ | ||||
| 699 | select id from ballot where poll = ? | ||||
| 700 | and invalid = true order by id | ||||
| 701 | } | ||||
| 702 | ); | ||||
| 703 | $sth->execute($self->voteid); | ||||
| 704 | my @ids; | ||||
| 705 | while (my $res = $sth->fetchrow_hashref) { | ||||
| 706 | push(@ids, $res->{id}); | ||||
| 707 | } | ||||
| 708 | @ids | ||||
| 709 | } | ||||
| 710 | |||||
| 711 | sub ballot_untrusted_values { | ||||
| 712 | my ($self, $noinvalid) = @_; | ||||
| 713 | |||||
| 714 | my $getval = $self->db->prepare_cached( | ||||
| 715 | q{ | ||||
| 716 | select value from ballot join ballot_item | ||||
| 717 | on ballot.id = ballot_item.id | ||||
| 718 | where poll = ? and fromlist = false | ||||
| 719 | } . ($noinvalid | ||||
| 720 | ? ' and (ballot.invalid = false or ballot.invalid is null) ' | ||||
| 721 | : '' | ||||
| 722 | ) . q{ | ||||
| 723 | group by value order by value | ||||
| 724 | } | ||||
| 725 | ); | ||||
| 726 | $getval->execute($self->voteid); | ||||
| 727 | my @vals; | ||||
| 728 | while (my $res = $getval->fetchrow_hashref) { | ||||
| 729 | push(@vals, $res->{value}); | ||||
| 730 | } | ||||
| 731 | @vals | ||||
| 732 | } | ||||
| 733 | |||||
| 734 | sub ballot_untrusted_ids { | ||||
| 735 | my ($self) = @_; | ||||
| 736 | |||||
| 737 | my $getval = $self->db->prepare_cached( | ||||
| 738 | q{ | ||||
| 739 | select ballot.id from ballot join ballot_item | ||||
| 740 | on ballot.id = ballot_item.id | ||||
| 741 | where poll = ? and fromlist = false | ||||
| 742 | group by ballot.id order by id | ||||
| 743 | } | ||||
| 744 | ); | ||||
| 745 | $getval->execute($self->voteid); | ||||
| 746 | my @vals; | ||||
| 747 | while (my $res = $getval->fetchrow_hashref) { | ||||
| 748 | push(@vals, $res->{id}); | ||||
| 749 | } | ||||
| 750 | @vals | ||||
| 751 | } | ||||
| 752 | |||||
| 753 | sub ballot_by_value { | ||||
| 754 | my ($self, $value) = @_; | ||||
| 755 | |||||
| 756 | my $getval = $self->db->prepare_cached( | ||||
| 757 | q{ | ||||
| 758 | select ballot.id from ballot join ballot_item on ballot.id = | ||||
| 759 | ballot_item.id | ||||
| 760 | where ballot.poll = ? and "value" = ? | ||||
| 761 | group by ballot.id order by id | ||||
| 762 | } | ||||
| 763 | ); | ||||
| 764 | $getval->execute($self->voteid, $value); | ||||
| 765 | my @vals; | ||||
| 766 | while (my $res = $getval->fetchrow_hashref) { | ||||
| 767 | push(@vals, $res->{id}); | ||||
| 768 | } | ||||
| 769 | @vals | ||||
| 770 | } | ||||
| 771 | |||||
| 772 | sub ballot_values { | ||||
| 773 | my ($self, $noinvalid) = @_; | ||||
| 774 | |||||
| 775 | my $getval = $self->db->prepare_cached( | ||||
| 776 | q{ | ||||
| 777 | select value as value from ballot join ballot_item | ||||
| 778 | on ballot.id = ballot_item.id | ||||
| 779 | where poll = ? | ||||
| 780 | } . ($noinvalid | ||||
| 781 | ? ' and (ballot.invalid = false or ballot.invalid is null) ' | ||||
| 782 | : '' | ||||
| 783 | ) . q{ | ||||
| 784 | group by value order by value | ||||
| 785 | } | ||||
| 786 | ); | ||||
| 787 | $getval->execute($self->voteid); | ||||
| 788 | my @vals; | ||||
| 789 | while (my $res = $getval->fetchrow_hashref) { | ||||
| 790 | push(@vals, $res->{value}); | ||||
| 791 | } | ||||
| 792 | @vals | ||||
| 793 | } | ||||
| 794 | |||||
| 795 | sub value_map_to { | ||||
| 796 | my ($self, $from) = @_; | ||||
| 797 | my $sth = $self->db->prepare_cached( | ||||
| 798 | q{select "to" from ballot_map where poll = ? and "from" = ?} | ||||
| 799 | ); | ||||
| 800 | $sth->execute($self->voteid, $from); | ||||
| 801 | my $res = $sth->fetchrow_hashref; | ||||
| 802 | $sth->finish; | ||||
| 803 | $res->{to} | ||||
| 804 | } | ||||
| 805 | |||||
| 806 | sub map_value { | ||||
| 807 | my ($self, $from, $to) = @_; | ||||
| 808 | |||||
| 809 | if (!$to) { | ||||
| 810 | my $sth = $self->db->prepare_cached( | ||||
| 811 | q{delete from ballot_map where poll = ? and "from" = ?} | ||||
| 812 | ); | ||||
| 813 | $sth->execute($self->voteid, $from); | ||||
| 814 | } else { | ||||
| 815 | my $sthup = $self->db->prepare_cached( | ||||
| 816 | q{update ballot_map set "to" = ? where poll = ? and "from" = ?} | ||||
| 817 | ); | ||||
| 818 | if ($sthup->execute($to, $self->voteid, $from) == 0) { | ||||
| 819 | my $sth = $self->db->prepare_cached( | ||||
| 820 | q{ | ||||
| 821 | insert into ballot_map (poll, "from", "to") values (?,?,?) | ||||
| 822 | } | ||||
| 823 | ); | ||||
| 824 | |||||
| 825 | $sth->execute($self->voteid, $from, $to) or do { | ||||
| 826 | $self->rollback; | ||||
| 827 | return; | ||||
| 828 | }; | ||||
| 829 | } | ||||
| 830 | } | ||||
| 831 | $self->commit; | ||||
| 832 | return 1; | ||||
| 833 | } | ||||
| 834 | |||||
| 835 | sub addupd_voting { | ||||
| 836 | my ($self, $mail, $id, $extern_auth, $extern_uid) = @_; | ||||
| 837 | |||||
| 838 | $mail =~ s/\s*$//; | ||||
| 839 | $mail =~ s/^\s*//; | ||||
| 840 | $mail = lc($mail); | ||||
| 841 | $id ||= ''; | ||||
| 842 | $id =~ s/\s*$//; | ||||
| 843 | $id =~ s/^\s//; | ||||
| 844 | my $upd = $self->db->prepare_cached( | ||||
| 845 | q{ | ||||
| 846 | update voting set label = ?, extern_auth = ?, extern_uid = ? where mail = ? and poll = ? | ||||
| 847 | } | ||||
| 848 | ); | ||||
| 849 | |||||
| 850 | if ($upd->execute($id, $extern_auth, $extern_uid, $mail, $self->voteid) == 0) { | ||||
| 851 | my $add = $self->db->prepare_cached(q{ | ||||
| 852 | insert into voting (poll, label, mail, extern_auth, extern_uid) | ||||
| 853 | values (?,?,?,?,?) | ||||
| 854 | }); | ||||
| 855 | |||||
| 856 | return $add->execute($self->voteid, $id || '', $mail, $extern_auth, $extern_uid); | ||||
| 857 | } else { | ||||
| 858 | return 1; | ||||
| 859 | } | ||||
| 860 | } | ||||
| 861 | |||||
| 862 | sub voting_from_file { | ||||
| 863 | my ($self, $fh, $delete) = @_; | ||||
| 864 | |||||
| 865 | if ($delete) { | ||||
| 866 | my $sth = $self->db->prepare(q{delete from voting where poll = ?}); | ||||
| 867 | $sth->execute($self->voteid); | ||||
| 868 | } | ||||
| 869 | |||||
| 870 | my $handle = $self->import_handle('csv'); # std import | ||||
| 871 | $handle->{handle} = $fh; | ||||
| 872 | my @list = $handle->fetch_voters or do { | ||||
| 873 | $self->rollback; | ||||
| 874 | return; | ||||
| 875 | }; | ||||
| 876 | foreach (@list) { | ||||
| 877 | $self->addupd_voting($_->[0], $_->[1] || ''); | ||||
| 878 | } | ||||
| 879 | 1; | ||||
| 880 | } | ||||
| 881 | |||||
| 882 | sub voting_from_import { | ||||
| 883 | my ($self, $handle, %options) = @_; | ||||
| 884 | |||||
| 885 | my $ext_auth = $options{ext_auth} && $handle->can_authenticate; | ||||
| 886 | my $authid; | ||||
| 887 | if ($ext_auth || $options{save_param}) { | ||||
| 888 | my $find_next_id = $self->db->prepare_cached( | ||||
| 889 | q{select nextval('extern_auth_id_seq'::regclass)} | ||||
| 890 | ); | ||||
| 891 | $find_next_id->execute(); | ||||
| 892 | $authid = $find_next_id->fetchrow_hashref->{nextval}; | ||||
| 893 | $find_next_id->finish; | ||||
| 894 | |||||
| 895 | my $add_auth = $self->db->prepare_cached( | ||||
| 896 | q{insert into extern_auth (id, params, owner, auth_type, "desc") values | ||||
| 897 | (?,?,?,?,?)} | ||||
| 898 | ); | ||||
| 899 | $add_auth->execute($authid, $handle->xml_params, $self->info('owner'), | ||||
| 900 | $handle->auth_type, $options{desc}); | ||||
| 901 | } | ||||
| 902 | |||||
| 903 | my @list = $handle->fetch_voters or do { | ||||
| 904 | $self->rollback; | ||||
| 905 | return; | ||||
| 906 | }; | ||||
| 907 | foreach (@list) { | ||||
| 908 | $self->addupd_voting( | ||||
| 909 | $_->[0], $_->[1] || '', $authid, ($ext_auth ? $_->[2]: undef) | ||||
| 910 | ) or do { | ||||
| 911 | $self->db->rollback; | ||||
| 912 | return; | ||||
| 913 | }; | ||||
| 914 | } | ||||
| 915 | |||||
| 916 | return 1; | ||||
| 917 | } | ||||
| 918 | |||||
| 919 | sub delete_voting { | ||||
| 920 | my ($self, $key) = @_; | ||||
| 921 | $self->voting($key)->has_sign and return; | ||||
| 922 | my $sth = $self->db->prepare_cached( | ||||
| 923 | q{delete from voting where key = ? and poll = ?} | ||||
| 924 | ); | ||||
| 925 | |||||
| 926 | $sth->execute($key, $self->voteid); | ||||
| 927 | } | ||||
| 928 | |||||
| 929 | # spent 6.45ms (236µs+6.22) within Epoll::DB::Poll::list_voting_no_passwd which was called
# once (236µs+6.22ms) by Epoll::Controller::Admin::voters at line 207 of Epoll/Controller/Admin.pm | ||||
| 930 | 1 | 3µs | my ($self) = @_; | ||
| 931 | |||||
| 932 | 1 | 71µs | 3 | 643µs | my $list_voting = $self->db->prepare_cached( # spent 244µs making 1 call to DBI::db::prepare_cached
# spent 223µs making 1 call to DBD::_::db::prepare_cached
# spent 176µs making 1 call to Epoll::DB::common::db |
| 933 | q{select key from voting where poll = ? and passwd is null or passwd = ''} | ||||
| 934 | ); | ||||
| 935 | |||||
| 936 | 1 | 5.53ms | 2 | 5.51ms | $list_voting->execute($self->voteid); # spent 5.50ms making 1 call to DBI::st::execute
# spent 10µs making 1 call to Epoll::DB::Poll::voteid |
| 937 | 1 | 2µs | my @ids; | ||
| 938 | 1 | 414µs | 12 | 432µs | while (my $res = $list_voting->fetchrow_hashref) { # spent 292µs making 4 calls to DBI::st::fetchrow_hashref, avg 73µs/call
# spent 73µs making 4 calls to DBI::st::fetch, avg 18µs/call
# spent 67µs making 4 calls to DBI::common::FETCH, avg 17µs/call |
| 939 | push(@ids, $res->{key}); | ||||
| 940 | } | ||||
| 941 | @ids | ||||
| 942 | 1 | 16µs | } | ||
| 943 | |||||
| 944 | sub mail_voting_passwd { | ||||
| 945 | my ($self, $id, $mailinfo) = @_; | ||||
| 946 | $self->voting($id)->mail_voting_passwd($mailinfo); | ||||
| 947 | } | ||||
| 948 | |||||
| 949 | # crypto part | ||||
| 950 | |||||
| 951 | sub rsa { | ||||
| 952 | my ($self) = @_; | ||||
| 953 | $self->{rsa} ||= new Crypt::RSA ES => 'PKCS1v15'; | ||||
| 954 | } | ||||
| 955 | |||||
| 956 | sub gen_poll_keys { | ||||
| 957 | my ($self, $password) = @_; | ||||
| 958 | my ($public, $private) = $self->rsa->keygen ( | ||||
| 959 | Identity => 'Epoll Vote ' . $self->voteid, | ||||
| 960 | Size => 768, | ||||
| 961 | Password => $password, | ||||
| 962 | Verbosity => 0, | ||||
| 963 | KF=>'SSH', | ||||
| 964 | ) or die $self->rsa->errstr(); # TODO avoid die | ||||
| 965 | $self->param( | ||||
| 966 | public_key => $public->serialize, | ||||
| 967 | private_key => encode_base64($private->serialize), | ||||
| 968 | ); | ||||
| 969 | } | ||||
| 970 | |||||
| 971 | sub public_key { | ||||
| 972 | my ($self) = @_; | ||||
| 973 | my $serialize = $self->info->{public_key} or return; | ||||
| 974 | my $pubkey = Crypt::RSA::Key::Public::SSH->new; | ||||
| 975 | $pubkey->deserialize(String => [ $serialize ]); | ||||
| 976 | $pubkey | ||||
| 977 | } | ||||
| 978 | |||||
| 979 | sub private_key { | ||||
| 980 | my ($self, $password) = @_; | ||||
| 981 | my $serialize = $self->info->{private_key} or return; | ||||
| 982 | my $privkey = Crypt::RSA::Key::Private::SSH->new; | ||||
| 983 | $privkey->deserialize(String => [ decode_base64($serialize) ], Passphrase => $password); | ||||
| 984 | $privkey | ||||
| 985 | } | ||||
| 986 | |||||
| 987 | |||||
| 988 | |||||
| 989 | ######### | ||||
| 990 | # Count # | ||||
| 991 | ######### | ||||
| 992 | |||||
| 993 | sub ballot_count { | ||||
| 994 | ballots_count(@_); | ||||
| 995 | } | ||||
| 996 | |||||
| 997 | sub ballots_count { | ||||
| 998 | my ($self) = @_; | ||||
| 999 | return $self->ballot_count_crypt; | ||||
| 1000 | } | ||||
| 1001 | |||||
| 1002 | sub ballot_count_clear { | ||||
| 1003 | my ($self) = @_; | ||||
| 1004 | |||||
| 1005 | my $sth = $self->db->prepare_cached( | ||||
| 1006 | q{select count(*) from ballot where poll = ?} | ||||
| 1007 | ); | ||||
| 1008 | |||||
| 1009 | $sth->execute($self->voteid); | ||||
| 1010 | my $res = $sth->fetchrow_hashref; | ||||
| 1011 | $sth->finish; | ||||
| 1012 | $res->{count} || 0 | ||||
| 1013 | } | ||||
| 1014 | |||||
| 1015 | sub ballot_count_crypt { | ||||
| 1016 | my ($self) = @_; | ||||
| 1017 | |||||
| 1018 | my $sth = $self->db->prepare_cached( | ||||
| 1019 | q{select count(*) from ballot_enc where poll = ?} | ||||
| 1020 | ); | ||||
| 1021 | |||||
| 1022 | $sth->execute($self->voteid); | ||||
| 1023 | my $res = $sth->fetchrow_hashref; | ||||
| 1024 | $sth->finish; | ||||
| 1025 | $res->{count} || 0 | ||||
| 1026 | } | ||||
| 1027 | |||||
| 1028 | 1 | 19µs | 1 | 4.80ms | # spent 4.82ms (20µs+4.80) within Epoll::DB::Poll::voting_count which was called
# once (20µs+4.80ms) by Template::Stash::XS::get at line 84 of Epoll/root/templates/admin/voters.tt # spent 4.80ms making 1 call to Epoll::DB::Poll::voters_count |
| 1029 | |||||
| 1030 | # spent 4.80ms (217µs+4.58) within Epoll::DB::Poll::voters_count which was called
# once (217µs+4.58ms) by Epoll::DB::Poll::voting_count at line 1028 | ||||
| 1031 | 1 | 3µs | my ($self) = @_; | ||
| 1032 | |||||
| 1033 | 1 | 141µs | 3 | 739µs | my $sth = $self->db->prepare_cached( # spent 316µs making 1 call to DBI::db::prepare_cached
# spent 294µs making 1 call to DBD::_::db::prepare_cached
# spent 129µs making 1 call to Epoll::DB::common::db |
| 1034 | q{ | ||||
| 1035 | select count(*) from voting | ||||
| 1036 | where poll = ? | ||||
| 1037 | } | ||||
| 1038 | ); | ||||
| 1039 | 1 | 4.03ms | 2 | 4.01ms | $sth->execute($self->voteid); # spent 4.00ms making 1 call to DBI::st::execute
# spent 11µs making 1 call to Epoll::DB::Poll::voteid |
| 1040 | 1 | 129µs | 3 | 159µs | my $res = $sth->fetchrow_hashref; # spent 112µs making 1 call to DBI::st::fetchrow_hashref
# spent 26µs making 1 call to DBI::st::fetch
# spent 22µs making 1 call to DBI::common::FETCH |
| 1041 | 1 | 28µs | 1 | 16µs | $sth->finish; # spent 16µs making 1 call to DBI::st::finish |
| 1042 | 1 | 21µs | $res->{count} | ||
| 1043 | } | ||||
| 1044 | |||||
| 1045 | sub signing_count { | ||||
| 1046 | my ($self) = @_; | ||||
| 1047 | |||||
| 1048 | my $sth = $self->db->prepare_cached( | ||||
| 1049 | q{ | ||||
| 1050 | select count(*) from signing join voting | ||||
| 1051 | on voting.key = signing.key where poll = ? | ||||
| 1052 | } | ||||
| 1053 | ); | ||||
| 1054 | |||||
| 1055 | $sth->execute($self->voteid); | ||||
| 1056 | my $res = $sth->fetchrow_hashref; | ||||
| 1057 | $sth->finish; | ||||
| 1058 | $res->{count} | ||||
| 1059 | } | ||||
| 1060 | |||||
| 1061 | sub not_signing_count { | ||||
| 1062 | my ($self) = @_; | ||||
| 1063 | $self->voters_count - $self->signing_count; | ||||
| 1064 | } | ||||
| 1065 | |||||
| 1066 | sub valid_ballot_count { | ||||
| 1067 | my ($self) = @_; | ||||
| 1068 | |||||
| 1069 | my $sth = $self->db->prepare_cached( | ||||
| 1070 | q{ | ||||
| 1071 | select count(*) from ballot where poll = ? | ||||
| 1072 | and (invalid = 'f' or invalid is NULL) | ||||
| 1073 | } | ||||
| 1074 | ); | ||||
| 1075 | |||||
| 1076 | $sth->execute($self->voteid); | ||||
| 1077 | my $res = $sth->fetchrow_hashref; | ||||
| 1078 | $sth->finish; | ||||
| 1079 | $res->{count} | ||||
| 1080 | } | ||||
| 1081 | |||||
| 1082 | sub invalid_ballot_count { | ||||
| 1083 | my ($self) = @_; | ||||
| 1084 | |||||
| 1085 | my $sth = $self->db->prepare_cached( | ||||
| 1086 | q{ | ||||
| 1087 | select count(*) from ballot where poll = ? | ||||
| 1088 | and invalid = 't' | ||||
| 1089 | } | ||||
| 1090 | ); | ||||
| 1091 | |||||
| 1092 | $sth->execute($self->voteid); | ||||
| 1093 | my $res = $sth->fetchrow_hashref; | ||||
| 1094 | $sth->finish; | ||||
| 1095 | $res->{count} || 0 | ||||
| 1096 | } | ||||
| 1097 | |||||
| 1098 | sub empty_ballot_count { | ||||
| 1099 | my ($self) = @_; | ||||
| 1100 | |||||
| 1101 | my $sth = $self->db->prepare_cached( | ||||
| 1102 | q{ | ||||
| 1103 | select count(*) from ballot where poll = ? | ||||
| 1104 | and id not in (select id from ballot_item) | ||||
| 1105 | and (invalid = 'false' or invalid is null) | ||||
| 1106 | } | ||||
| 1107 | ); | ||||
| 1108 | |||||
| 1109 | $sth->execute($self->voteid); | ||||
| 1110 | my $res = $sth->fetchrow_hashref; | ||||
| 1111 | $sth->finish; | ||||
| 1112 | $res->{count} | ||||
| 1113 | } | ||||
| 1114 | |||||
| 1115 | sub not_empty_ballot_count { | ||||
| 1116 | my ($self) = @_; | ||||
| 1117 | |||||
| 1118 | my $sth = $self->db->prepare_cached( | ||||
| 1119 | q{ | ||||
| 1120 | select count(*) from ballot where poll = ? | ||||
| 1121 | and id in (select id from ballot_item) | ||||
| 1122 | and (invalid = 'false' or invalid is null) | ||||
| 1123 | } | ||||
| 1124 | ); | ||||
| 1125 | |||||
| 1126 | $sth->execute($self->voteid); | ||||
| 1127 | my $res = $sth->fetchrow_hashref; | ||||
| 1128 | $sth->finish; | ||||
| 1129 | $res->{count} || 0 | ||||
| 1130 | } | ||||
| 1131 | |||||
| 1132 | sub compute_results { | ||||
| 1133 | my ($self) = @_; | ||||
| 1134 | $self->param('static_results', | ||||
| 1135 | YAML::Dump($self->_compute_results)); | ||||
| 1136 | } | ||||
| 1137 | |||||
| 1138 | sub results { | ||||
| 1139 | my ($self) = @_; | ||||
| 1140 | if (my $res = YAML::Load($self->info('static_results'))) { | ||||
| 1141 | return $res | ||||
| 1142 | } else { | ||||
| 1143 | return; | ||||
| 1144 | } | ||||
| 1145 | } | ||||
| 1146 | |||||
| 1147 | ################# | ||||
| 1148 | # CLEANING DATA # | ||||
| 1149 | ################# | ||||
| 1150 | |||||
| 1151 | sub delete_ballots { | ||||
| 1152 | my ($self) = @_; | ||||
| 1153 | |||||
| 1154 | $self->store_results; | ||||
| 1155 | $self->_delete_ballot; | ||||
| 1156 | $self->commit; | ||||
| 1157 | } | ||||
| 1158 | |||||
| 1159 | sub _delete_ballot { | ||||
| 1160 | my ($self) = @_; | ||||
| 1161 | |||||
| 1162 | foreach ( | ||||
| 1163 | q{delete from ballot_item where id in (select id from ballot where | ||||
| 1164 | ballot.poll = ?)}, | ||||
| 1165 | q{delete from ballot where poll = ?}, | ||||
| 1166 | q{delete from ballot_enc where poll = ?},) { | ||||
| 1167 | my $req = $self->db->prepare($_); | ||||
| 1168 | $req->execute($self->voteid) or return; | ||||
| 1169 | } | ||||
| 1170 | |||||
| 1171 | return 1; | ||||
| 1172 | } | ||||
| 1173 | |||||
| 1174 | =head1 AUTHOR | ||||
| 1175 | |||||
| 1176 | Thauvin Olivier | ||||
| 1177 | |||||
| 1178 | =head1 LICENSE | ||||
| 1179 | |||||
| 1180 | This library is free software, you can redistribute it and/or modify | ||||
| 1181 | it under the same terms as Perl itself or CeCILL. | ||||
| 1182 | |||||
| 1183 | =cut | ||||
| 1184 | |||||
| 1185 | 1 | 9µs | 1; | ||
# spent 2.23ms within Epoll::DB::Poll::CORE:crypt which was called
# once (2.23ms+0s) by Epoll::DB::Poll::auth_poll at line 554 of Epoll/DB/Poll.pm | |||||
# spent 101µs within Epoll::DB::Poll::CORE:match which was called 9 times, avg 11µs/call:
# 9 times (101µs+0s) by Epoll::DB::Poll::new at line 114 of Epoll/DB/Poll.pm, avg 11µs/call |