Skip to content

Instantly share code, notes, and snippets.

@Ghost-chu
Last active December 19, 2024 23:03
Show Gist options
  • Select an option

  • Save Ghost-chu/10f01aab255bce407327e8e2e21cc8cf to your computer and use it in GitHub Desktop.

Select an option

Save Ghost-chu/10f01aab255bce407327e8e2e21cc8cf to your computer and use it in GitHub Desktop.

Revisions

  1. Ghost-chu revised this gist Dec 19, 2024. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions untrustip.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    SELECT DISTINCT ban.peerIp
    FROM BanHistory ban
    WHERE
    ban.insertTime >= ?1 AND ban.insertTime <= ?2 AND ban.module LIKE '%ProgressCheatBlocker%'
    GROUP BY ban.peerIp, time_bucket(?4, ban.insertTime)
    HAVING COUNT(DISTINCT ban.userApplication.appId) >= ?3
  2. Ghost-chu created this gist Dec 19, 2024.
    41 changes: 41 additions & 0 deletions overdownload.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    WITH LatestSnapshots AS (
    SELECT DISTINCT ON (s.torrent, s.peer_ip, s.user_application)
    s.id,
    s.torrent,
    s.peer_ip,
    s.user_application,
    s.to_peer_traffic,
    s.last_time_seen
    FROM
    public.peer_history s
    WHERE
    s.last_time_seen >= ? AND s.to_peer_traffic > 0
    ORDER BY
    s.torrent, s.peer_ip, s.user_application, s.last_time_seen DESC
    ),
    AggregatedUploads AS (
    SELECT
    ls.torrent,
    ls.peer_ip,
    SUM(ls.to_peer_traffic) AS total_uploaded
    FROM
    LatestSnapshots ls
    GROUP BY
    ls.torrent, ls.peer_ip
    HAVING
    SUM(ls.to_peer_traffic) > 0
    )
    SELECT
    au.torrent,
    au.peer_ip,
    au.total_uploaded,
    t.size,
    (au.total_uploaded / t.size::float) * 100 AS upload_percentage
    FROM
    AggregatedUploads au
    JOIN
    public.torrent t ON au.torrent = t.id
    WHERE
    t.size::float > 0 AND au.total_uploaded > t.size::float * ?
    ORDER BY
    upload_percentage DESC;