Skip to content

Instantly share code, notes, and snippets.

/comparison.pl Secret

Created November 22, 2014 17:29
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/1a159246c0bc25518956 to your computer and use it in GitHub Desktop.
Save anonymous/1a159246c0bc25518956 to your computer and use it in GitHub Desktop.
# Old
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
order by id desc
limit ?
offset ?", @values, $limit, $offset
)->arrays->map(sub { $self->job_info($_->[0]) })->to_array;
}
# New
sub list_jobs {
my ($self, $offset, $limit, $options) = @_;
return $self->pg->db->query(
'select id
from minion_jobs
where (state = $1 or $1::text is null) and (task = $2 or $2::text is null)
order by id desc
limit $3
offset $4', @$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