mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(analytics): include render-only users in activity count query
This commit is contained in:
@@ -222,15 +222,22 @@ def query_users(q: str = "", sort: str = "requests", limit: int = 200) -> list[d
|
||||
with db.analytics_conn() as c:
|
||||
c.execute("ATTACH DATABASE ? AS settings", (db.SETTINGS_DB_PATH,))
|
||||
try:
|
||||
# Count any event kind (request OR render) as activity so the
|
||||
# table matches `active_users_7d` in query_summary — without
|
||||
# this, render-only users (e.g. cron-driven worker refreshes
|
||||
# before any edge traffic) appear in the count but not the
|
||||
# table, which looks like a bug.
|
||||
rows = c.execute(
|
||||
"""SELECT e.username AS username,
|
||||
COUNT(*) AS requests_7d,
|
||||
SUM(CASE WHEN e.kind='request' THEN 1 ELSE 0 END) AS requests_7d,
|
||||
MAX(e.ts) AS last_seen,
|
||||
AVG(e.latency_ms) AS avg_latency_ms,
|
||||
COALESCE(AVG(CASE WHEN e.kind='request'
|
||||
THEN e.latency_ms END), 0) AS avg_latency_ms,
|
||||
(SELECT u.github_avatar_url FROM settings.users u
|
||||
WHERE u.username = e.username) AS github_avatar_url
|
||||
FROM events e
|
||||
WHERE e.kind='request' AND e.ts >= ? AND e.username IS NOT NULL
|
||||
WHERE e.kind IN ('request', 'render')
|
||||
AND e.ts >= ? AND e.username IS NOT NULL
|
||||
GROUP BY e.username""",
|
||||
(week_ago,),
|
||||
).fetchall()
|
||||
|
||||
@@ -166,3 +166,21 @@ def test_queue_drops_when_full_and_counts(fresh, monkeypatch):
|
||||
for i in range(10):
|
||||
a.record_render("u", "composite", i)
|
||||
assert a._events_dropped == 7
|
||||
|
||||
|
||||
def test_query_users_includes_render_only_users(fresh):
|
||||
"""Render-only users (worker fired but no edge traffic yet) must still
|
||||
appear in the table — without this, `active_users_7d` says N while the
|
||||
table looks empty, which reads as a bug."""
|
||||
now = int(time.time())
|
||||
a.ingest_batch([
|
||||
{"ts": now - 60, "service": "generator", "kind": "render",
|
||||
"username": "alice", "widget": "composite", "latency_ms": 200},
|
||||
])
|
||||
users = a.query_users()
|
||||
assert len(users) == 1
|
||||
u = users[0]
|
||||
assert u["username"] == "alice"
|
||||
assert u["requests_7d"] == 0 # no request events yet
|
||||
assert u["last_seen"] == now - 60
|
||||
assert u["avg_latency_ms"] == 0 # latency only averages request events
|
||||
|
||||
Reference in New Issue
Block a user