← 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:35:55 2011

File /usr/lib/perl5/vendor_perl/5.10.1/Epoll/DB/Poll.pm
Statements Executed 37093
Statement Execution Time 3.31s
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
179431205ms1.96sEpoll::DB::Poll::::raw_infoEpoll::DB::Poll::raw_info
8392291.6ms2.59sEpoll::DB::Poll::::votingEpoll::DB::Poll::voting
8427378.4ms923msEpoll::DB::Poll::::statusEpoll::DB::Poll::status
89715650.6ms2.01sEpoll::DB::Poll::::infoEpoll::DB::Poll::info
35068138.4ms38.4msEpoll::DB::Poll::::voteidEpoll::DB::Poll::voteid
17661120.5ms20.5msEpoll::DB::Poll::::_online_fEpoll::DB::Poll::_online_f
85215519.5ms1.89sEpoll::DB::Poll::::uidEpoll::DB::Poll::uid
11115.6ms98.7msEpoll::DB::Poll::::voting_keysEpoll::DB::Poll::voting_keys
9114.69ms34.9msEpoll::DB::Poll::::newEpoll::DB::Poll::new
1114.45ms309msEpoll::DB::Poll::::BEGIN@8Epoll::DB::Poll::BEGIN@8
1114.20ms12.5msEpoll::DB::Poll::::BEGIN@10Epoll::DB::Poll::BEGIN@10
1113.95ms9.85msEpoll::DB::Poll::::BEGIN@15Epoll::DB::Poll::BEGIN@15
1112.33ms3.26msEpoll::DB::Poll::::BEGIN@13Epoll::DB::Poll::BEGIN@13
1122.23ms2.23msEpoll::DB::Poll::::CORE:cryptEpoll::DB::Poll::CORE:crypt (opcode)
30212.22ms35.4msEpoll::DB::Poll::::_infoEpoll::DB::Poll::_info
1111.45ms2.43msEpoll::DB::Poll::::BEGIN@16Epoll::DB::Poll::BEGIN@16
1111.44ms2.15msEpoll::DB::Poll::::BEGIN@12Epoll::DB::Poll::BEGIN@12
1111.41ms1.98msEpoll::DB::Poll::::BEGIN@9Epoll::DB::Poll::BEGIN@9
1111.33ms2.03msEpoll::DB::Poll::::BEGIN@14Epoll::DB::Poll::BEGIN@14
111236µs6.45msEpoll::DB::Poll::::list_voting_no_passwdEpoll::DB::Poll::list_voting_no_passwd
111217µs4.80msEpoll::DB::Poll::::voters_countEpoll::DB::Poll::voters_count
911155µs16.8msEpoll::DB::Poll::::typeEpoll::DB::Poll::type
912101µs101µsEpoll::DB::Poll::::CORE:matchEpoll::DB::Poll::CORE:match (opcode)
11164µs6.10msEpoll::DB::Poll::::auth_pollEpoll::DB::Poll::auth_poll
11154µs66µsEpoll::DB::Poll::::BEGIN@5Epoll::DB::Poll::BEGIN@5
11138µs226µsEpoll::DB::Poll::::BEGIN@17Epoll::DB::Poll::BEGIN@17
11133µs165µsEpoll::DB::Poll::::BEGIN@11Epoll::DB::Poll::BEGIN@11
11132µs88µsEpoll::DB::Poll::::BEGIN@6Epoll::DB::Poll::BEGIN@6
11130µs588µsEpoll::DB::Poll::::BEGIN@7Epoll::DB::Poll::BEGIN@7
11120µs4.82msEpoll::DB::Poll::::voting_countEpoll::DB::Poll::voting_count
0000s0sEpoll::DB::Poll::::_delete_ballotEpoll::DB::Poll::_delete_ballot
0000s0sEpoll::DB::Poll::::_register_signingEpoll::DB::Poll::_register_signing
0000s0sEpoll::DB::Poll::::add_choiceEpoll::DB::Poll::add_choice
0000s0sEpoll::DB::Poll::::addupd_votingEpoll::DB::Poll::addupd_voting
0000s0sEpoll::DB::Poll::::auth_votingEpoll::DB::Poll::auth_voting
0000s0sEpoll::DB::Poll::::ballotEpoll::DB::Poll::ballot
0000s0sEpoll::DB::Poll::::ballot_by_valueEpoll::DB::Poll::ballot_by_value
0000s0sEpoll::DB::Poll::::ballot_countEpoll::DB::Poll::ballot_count
0000s0sEpoll::DB::Poll::::ballot_count_clearEpoll::DB::Poll::ballot_count_clear
0000s0sEpoll::DB::Poll::::ballot_count_cryptEpoll::DB::Poll::ballot_count_crypt
0000s0sEpoll::DB::Poll::::ballot_keysEpoll::DB::Poll::ballot_keys
0000s0sEpoll::DB::Poll::::ballot_untrusted_idsEpoll::DB::Poll::ballot_untrusted_ids
0000s0sEpoll::DB::Poll::::ballot_untrusted_valuesEpoll::DB::Poll::ballot_untrusted_values
0000s0sEpoll::DB::Poll::::ballot_valuesEpoll::DB::Poll::ballot_values
0000s0sEpoll::DB::Poll::::ballots_countEpoll::DB::Poll::ballots_count
0000s0sEpoll::DB::Poll::::bdataEpoll::DB::Poll::bdata
0000s0sEpoll::DB::Poll::::bsubmitEpoll::DB::Poll::bsubmit
0000s0sEpoll::DB::Poll::::can_show_resultEpoll::DB::Poll::can_show_result
0000s0sEpoll::DB::Poll::::choiceEpoll::DB::Poll::choice
0000s0sEpoll::DB::Poll::::choicesEpoll::DB::Poll::choices
0000s0sEpoll::DB::Poll::::choices_keysEpoll::DB::Poll::choices_keys
0000s0sEpoll::DB::Poll::::compute_resultsEpoll::DB::Poll::compute_results
0000s0sEpoll::DB::Poll::::decrypted_ballotsEpoll::DB::Poll::decrypted_ballots
0000s0sEpoll::DB::Poll::::delete_ballotsEpoll::DB::Poll::delete_ballots
0000s0sEpoll::DB::Poll::::delete_choiceEpoll::DB::Poll::delete_choice
0000s0sEpoll::DB::Poll::::delete_votingEpoll::DB::Poll::delete_voting
0000s0sEpoll::DB::Poll::::empty_ballot_countEpoll::DB::Poll::empty_ballot_count
0000s0sEpoll::DB::Poll::::find_choice_keyEpoll::DB::Poll::find_choice_key
0000s0sEpoll::DB::Poll::::gen_poll_keysEpoll::DB::Poll::gen_poll_keys
0000s0sEpoll::DB::Poll::::invalid_ballot_countEpoll::DB::Poll::invalid_ballot_count
0000s0sEpoll::DB::Poll::::is_cryptedEpoll::DB::Poll::is_crypted
0000s0sEpoll::DB::Poll::::list_ballotEpoll::DB::Poll::list_ballot
0000s0sEpoll::DB::Poll::::list_ballot_encEpoll::DB::Poll::list_ballot_enc
0000s0sEpoll::DB::Poll::::list_ballot_invalidEpoll::DB::Poll::list_ballot_invalid
0000s0sEpoll::DB::Poll::::list_ballot_need_decEpoll::DB::Poll::list_ballot_need_dec
0000s0sEpoll::DB::Poll::::list_ballot_needvalidEpoll::DB::Poll::list_ballot_needvalid
0000s0sEpoll::DB::Poll::::list_ballot_validEpoll::DB::Poll::list_ballot_valid
0000s0sEpoll::DB::Poll::::mail_voting_passwdEpoll::DB::Poll::mail_voting_passwd
0000s0sEpoll::DB::Poll::::map_valueEpoll::DB::Poll::map_value
0000s0sEpoll::DB::Poll::::not_empty_ballot_countEpoll::DB::Poll::not_empty_ballot_count
0000s0sEpoll::DB::Poll::::not_signing_countEpoll::DB::Poll::not_signing_count
0000s0sEpoll::DB::Poll::::paramEpoll::DB::Poll::param
0000s0sEpoll::DB::Poll::::private_keyEpoll::DB::Poll::private_key
0000s0sEpoll::DB::Poll::::public_keyEpoll::DB::Poll::public_key
0000s0sEpoll::DB::Poll::::register_ballotEpoll::DB::Poll::register_ballot
0000s0sEpoll::DB::Poll::::resultsEpoll::DB::Poll::results
0000s0sEpoll::DB::Poll::::rsaEpoll::DB::Poll::rsa
0000s0sEpoll::DB::Poll::::set_settingsEpoll::DB::Poll::set_settings
0000s0sEpoll::DB::Poll::::setupEpoll::DB::Poll::setup
0000s0sEpoll::DB::Poll::::signingEpoll::DB::Poll::signing
0000s0sEpoll::DB::Poll::::signing_countEpoll::DB::Poll::signing_count
0000s0sEpoll::DB::Poll::::valid_ballot_countEpoll::DB::Poll::valid_ballot_count
0000s0sEpoll::DB::Poll::::value_map_toEpoll::DB::Poll::value_map_to
0000s0sEpoll::DB::Poll::::voting_from_fileEpoll::DB::Poll::voting_from_file
0000s0sEpoll::DB::Poll::::voting_from_importEpoll::DB::Poll::voting_from_import
0000s0sEpoll::DB::Poll::::voting_from_mailEpoll::DB::Poll::voting_from_mail
0000s0sEpoll::DB::Poll::::voting_has_signEpoll::DB::Poll::voting_has_sign
0000s0sEpoll::DB::Poll::::voting_infoEpoll::DB::Poll::voting_info
0000s0sEpoll::DB::Poll::::voting_info_idEpoll::DB::Poll::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::Poll;
2
3# $Id: Poll.pm 319 2010-06-01 08:48:29Z nanardon $
4
5386µs279µ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
use strict;
# spent 66µs making 1 call to Epoll::DB::Poll::BEGIN@5 # spent 12µs making 1 call to strict::import
6386µs2144µ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
use warnings;
# spent 88µs making 1 call to Epoll::DB::Poll::BEGIN@6 # spent 56µs making 1 call to warnings::import
7387µs21.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
use base 'Epoll::DB::common';
# spent 588µs making 1 call to Epoll::DB::Poll::BEGIN@7 # spent 558µs making 1 call to base::import
83479µs2309ms
# 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
use Crypt::RSA;
# spent 309ms making 1 call to Epoll::DB::Poll::BEGIN@8 # spent 9µs making 1 call to UNIVERSAL::import
93562µs21.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
use Crypt::RSA::Key::Public::SSH;
# spent 1.98ms making 1 call to Epoll::DB::Poll::BEGIN@9 # spent 8µs making 1 call to UNIVERSAL::import
103514µs212.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
use Crypt::RSA::Key::Private::SSH;
# spent 12.5ms making 1 call to Epoll::DB::Poll::BEGIN@10 # spent 8µs making 1 call to UNIVERSAL::import
113141µs2296µ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
use MIME::Base64;
# spent 165µs making 1 call to Epoll::DB::Poll::BEGIN@11 # spent 132µs making 1 call to Exporter::import
123436µs22.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
use Epoll::DB::Ballot;
# spent 2.15ms making 1 call to Epoll::DB::Poll::BEGIN@12 # spent 83µs making 1 call to Exporter::import
133315µs23.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
use Epoll::DB::Voting;
# spent 3.26ms making 1 call to Epoll::DB::Poll::BEGIN@13 # spent 104µs making 1 call to Exporter::import
143521µs22.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
use Epoll::DB::Choice;
# spent 2.03ms making 1 call to Epoll::DB::Poll::BEGIN@14 # spent 78µs making 1 call to Exporter::import
153559µs29.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
use Epoll::DB::Poll::Bdata;
# spent 9.85ms making 1 call to Epoll::DB::Poll::BEGIN@15 # spent 140µs making 1 call to Exporter::import
163444µs22.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
use Epoll::DB::Poll::BSubmit;
# spent 2.43ms making 1 call to Epoll::DB::Poll::BEGIN@16 # spent 85µs making 1 call to Exporter::import
17317.1ms2415µ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
use YAML;
# 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
21Epoll::Model::Vote - Catalyst Model
22
23=head1 DESCRIPTION
24
25Catalyst Model.
26
27=head1 POLL PROPERTIES
28
29=head2 INLINES PROPERTIES
30
31=over 4
32
33=item id
34
35Unique identifier
36
37=item label
38
39The poll label
40
41=item start
42
43The timestamp when poll start
44
45=item end
46
47The timestamp when poll stop
48
49=item password
50
51The poll password encrypted using crypt()
52
53=item owner
54
55The mail of the owner
56
57=back
58
59=head2 EXTENDED PROPERTIES
60
61=over 4
62
63=item uid
64
65The anonyme uid of the poll (to use in url)
66
67=item choice_count
68
69The count of possible choice in ballot
70
71=item elected_choice
72
73Count of select from voting list
74
75=item free_choice
76
77The count of free text input on ballot
78
79=item description
80
81The long description of the poll
82
83=item procedure
84
85A text about rules of the poll
86
87=item private_key
88
89The RSA private key of the poll (if any)
90
91=item public_key
92
93The RSA public key of the poll (if any)
94
95=item no_mail_confirm_vote
96
97Do not sent mail to voting to confirm vote
98
99=item no_mail_ballot_id
100
101Don't include ballot id in mail confirmation
102
103=item no_ballot_id_voting
104
105Do 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
sub new {
112721.64ms my ($class, $dbstring, $voteid) = @_;
113
114 $voteid && $voteid =~ /^\d+$/ or return;
# spent 101µs making 9 calls to Epoll::DB::Poll::CORE:match, avg 11µs/call
115
116 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 my $type = $poll->type;
# spent 16.8ms making 9 calls to Epoll::DB::Poll::type, avg 1.87ms/call
123
124 $type = ucfirst(lc($type));
1251871µs eval "require Epoll::DB::Poll::Type::$type;";
126 if ($@) {
127 return;
128 } else {
129 return bless($poll, "Epoll::DB::Poll::Type::$type");
130 }
131}
132
1339137µs916.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
sub type { lc($_[0]->info('type') || 'binary') }
# spent 16.7ms making 9 calls to Epoll::DB::Poll::info, avg 1.85ms/call
134
135350645.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
sub voteid { $_[0]->{voteid} }
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
sub uid {
138170419.5ms my ($self) = @_;
139 # UID will come only with epoll 2.0, if no uid, using key
140 return $self->info('uid') || $self->voteid;
# spent 1.87s making 852 calls to Epoll::DB::Poll::info, avg 2.20ms/call
141}
142
143sub 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
152176630.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
sub _online_f { qw(label start end owner password) }
153
154sub 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
sub status {
1835894709ms my ($self) = @_;
184
185110.9ms2526283ms 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 $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 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 $sth->finish;
# spent 16.4ms making 842 calls to DBI::st::finish, avg 19µs/call
196 $res or return;
197 if ($res->{before}) {
198 return 'BEFORE';
199 } elsif ($res->{after}) {
200 return 'AFTER';
201 } else {
202 return 'RUNNING';
203 }
204}
205
206
# spent 35.4ms (2.22+33.2) within Epoll::DB::Poll::_info which was called 30 times, avg 1.18ms/call: # 28 times (2.12ms+31.7ms) by Epoll::DB::Poll::raw_info at line 243, avg 1.21ms/call # 2 times (100µs+1.44ms) by Epoll::DB::Poll::raw_info at line 230, avg 768µs/call
sub _info {
20718029.3ms my ($self) = @_;
208
2091474µs907.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 $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 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 $sth->finish;
# spent 455µs making 30 calls to DBI::st::finish, avg 15µs/call
223 $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
sub raw_info {
227143141.46s my ($self, $var) = @_;
228
229 if ($var) {
230 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 {
233122.2ms5292566ms 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 $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 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 $sth->finish;
# spent 35.4ms making 1764 calls to DBI::st::finish, avg 20µs/call
239 return $res->{val}
240 }
241 }
242
243 if (my $res = $self->_info) {
# spent 33.9ms making 28 calls to Epoll::DB::Poll::_info, avg 1.21ms/call
2441223µs847.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 $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 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 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
sub info {
257454147.5ms my ($self, $var) = @_;
258
259 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 if ($var) {
# spent 71.8ms making 28 calls to Epoll::DB::Poll::raw_info, avg 2.56ms/call
265 my $val = $self->raw_info($var);
# spent 916ms making 869 calls to Epoll::DB::Poll::raw_info, avg 1.05ms/call
266 return defined($val)
267 ? $val
268 : $default->{$var};
269 } elsif (my $res = $self->raw_info) {
270 foreach (keys %$default) {
271 $res->{$_} = $default->{$_} if (!defined($res->{$_}));
272 }
273 return $res
274 }
275 return;
276}
277
278sub 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
295sub 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
sub voting {
3145034791ms my ($self, $votingkey) = @_;
315
316111.7ms2517300ms 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 $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 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 $sth->finish;
# spent 17.5ms making 839 calls to DBI::st::finish, avg 21µs/call
325 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
328sub 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
sub voting_keys {
344698.2ms my ($self) = @_;
345
346172µs3708µ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 $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 my @people;
354 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}
359
360sub 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
377sub 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
391sub 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
409sub 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
426sub 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
441sub 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
451sub _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
469sub 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
481sub 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
500sub 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
519sub is_crypted {
520 my ($self) = @_;
521 return $self->info->{public_key} ? 1 : 0;
522}
523
524sub 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
538sub 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
sub auth_poll {
54852.29ms my ($self, $passwd) = @_;
549
550 my $vinfo = $self->info or return;
# spent 3.80ms making 1 call to Epoll::DB::Poll::info
551
552 $vinfo->{password} or return;
553 $passwd or return;
554 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
561sub voting_has_sign {
562 my ($self, $user) = @_;
563 $self->voting_from_mail($user)->has_sign;
564}
565
566# Requete de decompte des voix:
567
568sub 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
579sub bdata {
580 my ($self) = @_;
581 Epoll::DB::Poll::Bdata->new($self->{dbstring}, $self);
582}
583
584sub bsubmit {
585 my ($self) = @_;
586 Epoll::DB::Poll::BSubmit->new($self->{dbstring}, $self);
587}
588
589sub 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:
605sub list_ballot {
606 ballot_keys(@_);
607}
608
609sub 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
626sub 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
643sub 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
660sub 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
677sub 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
694sub 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
711sub 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
734sub 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
753sub 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
772sub 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
795sub 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
806sub 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
835sub 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
862sub 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
882sub 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
919sub 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
sub list_voting_no_passwd {
93065.99ms my ($self) = @_;
931
932149µs3643µ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 $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 my @ids;
938 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}
943
944sub mail_voting_passwd {
945 my ($self, $id, $mailinfo) = @_;
946 $self->voting($id)->mail_voting_passwd($mailinfo);
947}
948
949# crypto part
950
951sub rsa {
952 my ($self) = @_;
953 $self->{rsa} ||= new Crypt::RSA ES => 'PKCS1v15';
954}
955
956sub 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
971sub 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
979sub 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
993sub ballot_count {
994 ballots_count(@_);
995}
996
997sub ballots_count {
998 my ($self) = @_;
999 return $self->ballot_count_crypt;
1000}
1001
1002sub 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
1015sub 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
1028119µs14.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
sub voting_count { voters_count(@_) }
# 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
sub voters_count {
103164.24ms my ($self) = @_;
1032
10331119µs3739µ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 $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 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 $sth->finish;
# spent 16µs making 1 call to DBI::st::finish
1042 $res->{count}
1043}
1044
1045sub 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
1061sub not_signing_count {
1062 my ($self) = @_;
1063 $self->voters_count - $self->signing_count;
1064}
1065
1066sub 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
1082sub 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
1098sub 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
1115sub 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
1132sub compute_results {
1133 my ($self) = @_;
1134 $self->param('static_results',
1135 YAML::Dump($self->_compute_results));
1136}
1137
1138sub 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
1151sub delete_ballots {
1152 my ($self) = @_;
1153
1154 $self->store_results;
1155 $self->_delete_ballot;
1156 $self->commit;
1157}
1158
1159sub _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
1176Thauvin Olivier
1177
1178=head1 LICENSE
1179
1180This library is free software, you can redistribute it and/or modify
1181it under the same terms as Perl itself or CeCILL.
1182
1183=cut
1184
118519µs1;
# 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
sub Epoll::DB::Poll::CORE:crypt; # xsub
# 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
sub Epoll::DB::Poll::CORE:match; # xsub