Skip to content

Optimize promos a bit #2297

@michalrus

Description

@michalrus

When refreshing promotions for a customer, what I’d like to do is:

  1. Get IDs of all groups the customer belongs to:

    1. from Postgres — trivial

    2. from ES — less so; we can use a multi-search to get rid of round-trips, but there’s no way to short-circuit a query, when its first result is found, confirmed by Mark Walkom from ES:

      07:02 <michalrus> Hey, I have N queries, and would like to know about each if it has 0 or non-0 results. Can this be done in 1 request? I guess I could use _msearch. But is there anything more performant than checking length of results for a given search and later comparing it with 0? If ES finds at least one result, it could short-circuit in my case.

      08:37 <@warkolm> michalrus: there's no other way

  2. Only then use those IDs when checking promotion applicability.

This is still inefficient, but at least not as inefficient as the current code. When we decide to go with caching one day, this code should be useful then, too. :)

/cc @Anna-ZZZ

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions