Skip to content

Instantly share code, notes, and snippets.

/optimal.diff Secret

Created November 22, 2014 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c2f9625dc0e26a38b3b1 to your computer and use it in GitHub Desktop.
Save anonymous/c2f9625dc0e26a38b3b1 to your computer and use it in GitHub Desktop.
diff --git a/lib/Minion/Backend/Pg.pm b/lib/Minion/Backend/Pg.pm
index 6e974f5..d15ceaf 100644
--- a/lib/Minion/Backend/Pg.pm
+++ b/lib/Minion/Backend/Pg.pm
@@ -59,19 +59,22 @@ sub job_info {
sub list_jobs {
my ($self, $offset, $limit, $options) = @_;
- my (@and, @values);
- push @and, 'state = ?' and push @values, $options->{state}
- if $options->{state};
- push @and, 'task = ?' and push @values, $options->{task} if $options->{task};
- my $where = @and ? 'where ' . join(' and ', @and) : '';
+ warn $self->pg->db->query(
+ 'explain analyze select id
+ from minion_jobs
+ where (state = ? or ?::text is null) and (task = ? or ?::text is null)
+ order by id desc
+ limit ?
+ offset ?', @$options{qw(state state task task)}, $limit, $offset
+ )->arrays->flatten->join;
return $self->pg->db->query(
- "select id
+ 'select id
from minion_jobs
- $where
+ where (state = ? or ?::text is null) and (task = ? or ?::text is null)
order by id desc
limit ?
- offset ?", @values, $limit, $offset
+ offset ?', @$options{qw(state state task task)}, $limit, $offset
)->arrays->map(sub { $self->job_info($_->[0]) })->to_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment