DB optimization
This commit is contained in:
parent
3ff0f7b936
commit
68268a51b5
19
II/DB.pm
19
II/DB.pm
@ -20,6 +20,22 @@ sub new {
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub begin {
|
||||
my ($self) = @_;
|
||||
my $dbh = $self->{_dbh};
|
||||
|
||||
# Begin transaction
|
||||
$dbh->do('BEGIN');
|
||||
}
|
||||
|
||||
sub commit {
|
||||
my ($self) = @_;
|
||||
my $dbh = $self->{_dbh};
|
||||
|
||||
# Commmit transaction
|
||||
$dbh->do('COMMIT');
|
||||
}
|
||||
|
||||
sub write_out {
|
||||
my ( $self, %data ) = @_;
|
||||
my $dbh = $self->{_dbh};
|
||||
@ -51,8 +67,7 @@ sub write {
|
||||
|
||||
my $sth = $dbh->prepare($stmt);
|
||||
$sth->execute(@bind);
|
||||
|
||||
print "Message writed to DB!\n";
|
||||
$sth->finish();
|
||||
}
|
||||
|
||||
sub select_out {
|
||||
|
@ -63,6 +63,10 @@ sub get_echo {
|
||||
= "<!DOCTYPE html><meta charset=utf8><body><h1>Новые сообщения</h1>\n";
|
||||
if ( defined($msgs) ) {
|
||||
my @msg_list = split /\n/, $msgs;
|
||||
|
||||
# Begin transaction
|
||||
print "Writing messages\n";
|
||||
$db->begin();
|
||||
while (<@msg_list>) {
|
||||
my $mes_hash = $_;
|
||||
|
||||
@ -104,9 +108,10 @@ sub get_echo {
|
||||
|
||||
# Write message to DB
|
||||
$db->write(%data);
|
||||
|
||||
# $new_messages .= "$post</p>";
|
||||
}
|
||||
# Commit transaction
|
||||
$db->commit();
|
||||
print "Messages writed to DB!\n";
|
||||
}
|
||||
return $msgs;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user