-
-
Save anonymous/d2e10692069a9f115d66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/Pg/Database.pm b/lib/Mojo/Pg/Database.pm | |
index 3450457..eb22cd9 100644 | |
--- a/lib/Mojo/Pg/Database.pm | |
+++ b/lib/Mojo/Pg/Database.pm | |
@@ -71,7 +71,7 @@ sub query { | |
# Blocking | |
unless ($cb) { | |
- my $sth = $self->_dequeue(0, $query); | |
+ my $sth = $self->_dequeue(0, delete $self->{server}, $query); | |
$sth->execute(@_); | |
$self->_notifications; | |
return Mojo::Pg::Results->new(db => $self, sth => $sth); | |
@@ -82,6 +82,12 @@ sub query { | |
$self->$_ for qw(_next _watch); | |
} | |
+sub server_prepare { | |
+ my $self = shift; | |
+ $self->{server} = 1; | |
+ return $self; | |
+} | |
+ | |
sub unlisten { | |
my ($self, $name) = @_; | |
@@ -95,16 +101,19 @@ sub unlisten { | |
} | |
sub _dequeue { | |
- my ($self, $async, $query) = @_; | |
+ my ($self, $async, $server, $query) = @_; | |
my $queue = $self->{queue} ||= []; | |
for (my $i = 0; $i <= $#$queue; $i++) { | |
my $sth = $queue->[$i]; | |
- return splice @$queue, $i, 1 | |
- if !(!$sth->{pg_async} ^ !$async) && $sth->{Statement} eq $query; | |
+ next if $server && !$sth->{pg_server_prepare}; | |
+ next if !$sth->{pg_async} ^ !$async; | |
+ return splice @$queue, $i, 1 if $sth->{Statement} eq $query; | |
} | |
- return $self->dbh->prepare($query, $async ? {pg_async => PG_ASYNC} : ()); | |
+ my $dbh = $self->dbh; | |
+ local $dbh->{pg_server_prepare} = 1 if $server; | |
+ return $dbh->prepare($query, $async ? {pg_async => PG_ASYNC} : ()); | |
} | |
sub _enqueue { | |
@@ -119,7 +128,7 @@ sub _next { | |
return unless my $next = $self->{waiting}[0]; | |
return if $next->{sth}; | |
- my $sth = $next->{sth} = $self->_dequeue(1, $next->{query}); | |
+ my $sth = $next->{sth} = $self->_dequeue(1, 0, $next->{query}); | |
$sth->execute(@{$next->{args}}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment