azure_cdn: use subgroups, attempt 3

This commit is contained in:
Iain Learmonth 2022-04-25 15:06:24 +01:00
parent 95a39f759a
commit 7eb2eaf36f

View file

@ -1,6 +1,8 @@
import datetime
from collections import defaultdict
from sqlalchemy import text
from app import app
from app.extensions import db
from app.models.base import Group
@ -11,13 +13,13 @@ from app.terraform import BaseAutomation
class ProxyAutomation(BaseAutomation):
def get_subgroups(self):
conn = db.engine.connect()
result = conn.execute("""
result = conn.execute(text("""
SELECT origin.group_id, proxy.psg, COUNT(proxy.id) FROM proxy, origin
WHERE proxy.origin_id = origin.id
AND proxy.destroyed IS NULL
AND proxy.provider = :provider
GROUP BY origin.group_id, proxy.psg;
""", provider=self.provider)
"""), provider=self.provider)
subgroups = defaultdict(lambda: defaultdict(lambda: 0))
for row in result:
subgroups[row[0]][row[1]] = row[2]