Skip to content

Instantly share code, notes, and snippets.

/coalesce.diff Secret

Created November 22, 2014 16:08
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/17c40715f7c407b184e0 to your computer and use it in GitHub Desktop.
Save anonymous/17c40715f7c407b184e0 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..7e7c641 100644
--- a/lib/Minion/Backend/Pg.pm
+++ b/lib/Minion/Backend/Pg.pm
@@ -59,19 +59,13 @@ 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) : '';
-
return $self->pg->db->query(
"select id
from minion_jobs
- $where
+ where state = coalesce(?, state) and task = coalesce(?, task)
order by id desc
limit ?
- offset ?", @values, $limit, $offset
+ offset ?", @$options{qw(state 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