Update public source

This commit is contained in:
2026-10-14 06:09:52 +03:00
parent b33d51f24f
commit 95a0f6e75a
+56 -43
View File
@@ -124,30 +124,38 @@ def load_access_points(conn):
if not rows:
return []
access_point_ids = [
row["id"]
for row in rows
]
placeholders = ",".join(
"?" for _ in access_point_ids
)
credentials = query_all(
conn,
f"""
"""
WITH latest_observations AS (
SELECT
access_point_id,
password,
source,
verified
FROM credentials
WHERE access_point_id IN ({placeholders})
obs.access_point_id,
ROW_NUMBER() OVER (
PARTITION BY obs.access_point_id
ORDER BY
created_at DESC,
id DESC
obs.observed_at DESC,
obs.id DESC
) AS rn
FROM access_point_observations AS obs
WHERE
obs.latitude IS NOT NULL
AND obs.longitude IS NOT NULL
AND obs.latitude != 0
AND obs.longitude != 0
)
SELECT
c.access_point_id,
c.password,
c.source,
c.verified
FROM credentials AS c
JOIN latest_observations AS obs
ON obs.access_point_id = c.access_point_id
AND obs.rn = 1
ORDER BY
c.created_at DESC,
c.id DESC
""",
access_point_ids,
)
credentials_by_ap = {}
@@ -165,35 +173,40 @@ def load_access_points(conn):
"verified": credential["verified"],
})
session_conditions = []
session_parameters = []
for row in rows:
session_conditions.append(
"(access_point_id = ? AND session_id = ?)"
)
session_parameters.extend([
row["id"],
row["session_id"],
])
handshakes = query_all(
conn,
f"""
"""
WITH ranked_observations AS (
SELECT
access_point_id,
session_id,
type,
captured_at
FROM handshakes
WHERE {" OR ".join(session_conditions)}
obs.access_point_id,
obs.session_id,
ROW_NUMBER() OVER (
PARTITION BY obs.access_point_id
ORDER BY
captured_at DESC,
id DESC
obs.observed_at DESC,
obs.id DESC
) AS rn
FROM access_point_observations AS obs
WHERE
obs.latitude IS NOT NULL
AND obs.longitude IS NOT NULL
AND obs.latitude != 0
AND obs.longitude != 0
)
SELECT
hs.access_point_id,
hs.session_id,
hs.type,
hs.captured_at
FROM handshakes AS hs
JOIN ranked_observations AS obs
ON obs.access_point_id = hs.access_point_id
AND obs.session_id = hs.session_id
AND obs.rn = 1
ORDER BY
hs.captured_at DESC,
hs.id DESC
""",
session_parameters,
)
handshakes_by_ap_session = {}