~ihabunek/triglav

ec69d6f9aa18a9b0df708ac31927f0f2d138f2d5 — Ivan Habunek 4 months ago f747476
Improve performance of use_count update
1 files changed, 7 insertions(+), 5 deletions(-)

M lib/triglav/autotrolej/import.ex
M lib/triglav/autotrolej/import.ex => lib/triglav/autotrolej/import.ex +7 -5
@@ 153,12 153,14 @@ defmodule Triglav.Autotrolej.Import do
    Repo.query!(
      """
      UPDATE pt_platforms AS p
      SET use_count = (
        SELECT count(*)
      SET use_count = tmp.count
      FROM (
        SELECT platform_id, count(*) AS count
        FROM pt_route_variant_platforms
        WHERE platform_id = p.id
      )
      WHERE feed_id = $1
        WHERE feed_id = $1
        GROUP BY 1
      ) AS tmp
      WHERE tmp.platform_id = p.id AND p.feed_id = $1;
      """,
      [feed_id]
    )