Fine print: "O(N) where N is the number of elements to be removed by the
operation."
-> O(1)
And it's 1 request vs 2 (llen + lpop)

don't we want to remove from the left, because new failures are added to
the right ?


On Mon, May 20, 2013 at 9:19 AM, mathieulaporte <notifications@github.com>wrote:

> In lib/sidekiq/failures/middleware.rb:
>
> > @@ -19,7 +30,12 @@ def call(worker, msg, queue)
> >            :queue => queue
> >          }
> >
> > -        Sidekiq.redis { |conn| conn.lpush(:failed, Sidekiq.dump_json(data)) }
> > +        Sidekiq.redis do |conn|
> > +          conn.rpush(:failed, Sidekiq.dump_json(data))
> > +          unless Sidekiq::Failures::Config.max_failures_count.nil?
> > +            conn.lpop(:failed) if conn.llen(:failed) > Config.max_failures_count
>
> I don't use ltrim because this function removes elements from the left,
> and the newest failures are added from the right. It may be possible to do
> some thing with negative value in params but ltrim is a O(N) operation and
> lpop a O(1).
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/mhfs/sidekiq-failures/pull/25/files#r4300019>
> .
>