j f d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZmZm Z m Z mZmZm Z mZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d Zed z ZdZ e Z ej d Z G d de Z ddZ!d Z"d Z#d Z$d Z%d Z&ddZ'd Z(d Z)d Z*ej+ defd Z,dS ) N)datetime timedelta) ColumnBooleanDateTimeIntegerString create_engineeventfunctext)declarative_base) Inspector)Session)close_all_sessions) DatabaseErrorz/var/lve/ssa.dbz.old cleanup_old_datac e Zd ZdZdZ eed Z eedd Z eedd Z eed Z eed Z ee d Z ee d Z eed Z eed Z ee d Z e ed ej d Z e ed ej ej ZdS ) RequestResultay Describes processed request stored in database file. E.g. { "timestamp": "1650008727", "url": "http://mydomain.com/index.php", "duration": 162077, "hitting_limits": false, "throttled_time": 0, "io_throttled_time": 0, "wordpress": true } Note: created_at, updated_at is saved in local TZ format scrape_resultT)primary_keyF)indexnullable)r )timezone)server_defaultr )onupdater N)__name__ __module____qualname____doc__ __tablename__r r idr domainpath timestampdurationr is_slow_requesthitting_limitsthrottled_timeio_throttled_time wordpressr r now created_at updated_at =/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/db.pyr r ' sR $M T * * *B VF$ 7 7 7F6&u555Dw///Ivg...HfWu555OVGe444NVGe444Nw777w///I $/// RVWWWJ$///($(**U]UYU]U_U_```JJJr1 r ' c t j t t z }d} t | 5 }| t d ||d }|j }||z }|dk r ddd n ddd n# 1 swxY w Y nt d| t | dS )a Removes outdated records from database, saving disk space. Deletions are batched to avoid loading the entire database into the cgroup's page cache, which causes OOM on large databases. Runs VACUUM after deletion to reclaim disk space. )daysr TzrDELETE FROM scrape_result WHERE rowid IN (SELECT rowid FROM scrape_result WHERE created_at < :cutoff LIMIT :batch))cutoffbatchNzCleanup deleted %d old records)r todayr RETENTION_TIME_DAYS session_scopeexecuter rowcountloggerinfovacuum_database)engine batch_size n_days_ago total_deletedsessionresultdeleteds r2 r r M s5 !!I3F$G$G$GGJM 6 " " g__T\& & %z::<