dbs: add last_seen column to proxylist
This commit is contained in:
14
dbs.py
14
dbs.py
@@ -88,6 +88,16 @@ def _migrate_protos_working(sqlite):
|
||||
sqlite.commit()
|
||||
|
||||
|
||||
def _migrate_last_seen(sqlite):
|
||||
"""Add last_seen column for worker-reported proxy freshness tracking."""
|
||||
try:
|
||||
sqlite.execute('SELECT last_seen FROM proxylist LIMIT 1')
|
||||
except Exception:
|
||||
# last_seen: unix timestamp of most recent "working" report from any worker
|
||||
sqlite.execute('ALTER TABLE proxylist ADD COLUMN last_seen INT DEFAULT 0')
|
||||
sqlite.commit()
|
||||
|
||||
|
||||
def compute_proxy_list_hash(proxies):
|
||||
"""Compute MD5 hash of sorted proxy list for change detection.
|
||||
|
||||
@@ -315,7 +325,8 @@ def create_table_if_not_exists(sqlite, dbname):
|
||||
confidence INT DEFAULT 30,
|
||||
source_proto TEXT,
|
||||
source_confidence INT DEFAULT 0,
|
||||
protos_working TEXT)""")
|
||||
protos_working TEXT,
|
||||
last_seen INT DEFAULT 0)""")
|
||||
# Migration: add columns to existing databases (must run before creating indexes)
|
||||
_migrate_latency_columns(sqlite)
|
||||
_migrate_anonymity_columns(sqlite)
|
||||
@@ -324,6 +335,7 @@ def create_table_if_not_exists(sqlite, dbname):
|
||||
_migrate_confidence_column(sqlite)
|
||||
_migrate_source_proto(sqlite)
|
||||
_migrate_protos_working(sqlite)
|
||||
_migrate_last_seen(sqlite)
|
||||
# Indexes for common query patterns
|
||||
sqlite.execute('CREATE INDEX IF NOT EXISTS idx_proxylist_failed ON proxylist(failed)')
|
||||
sqlite.execute('CREATE INDEX IF NOT EXISTS idx_proxylist_tested ON proxylist(tested)')
|
||||
|
||||
Reference in New Issue
Block a user