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] )