lib/picky/backends/redis.rb in picky-3.6.10 vs lib/picky/backends/redis.rb in picky-3.6.11

- old
+ new

@@ -154,30 +154,38 @@ identifiers << "#{combination.identifier}" end result_id = generate_intermediate_result_id - # Intersect and store. + # Little optimization. # - intersected = client.zinterstore result_id, identifiers - - # Return clean and early if there has been no intersection. + # TODO Include in the scripting version as well. # - if intersected.zero? - client.del result_id - return [] - end + if identifiers.size > 1 + # Intersect and store. + # + intersected = client.zinterstore result_id, identifiers - # Get the stored result. - # - results = client.zrange result_id, offset, (offset + amount) + # Return clean and early if there has been no intersection. + # + if intersected.zero? + client.del result_id + return [] + end - # Delete the stored result as it was only for temporary purposes. - # - # Note: I could also not delete it, but that - # would not be clean at all. - # - client.del result_id + # Get the stored result. + # + results = client.zrange result_id, offset, (offset + amount) + + # Delete the stored result as it was only for temporary purposes. + # + # Note: I could also not delete it, but that + # would not be clean at all. + # + client.del result_id + else + results = client.zrange identifiers.first, offset, (offset + amount) + end results end end end \ No newline at end of file