Gather .health instance stats

Reworks instance checks to use the same timestamp and be transactional. Also prevents long DB lock times during list updates.
This commit is contained in:
4cuck committed 2023-11-27 00:27:07 +01:00
1 parent 07ae70124e
commit 98ac43723e
22 files changed
+601 -90

No files matched your search

+2
View File
@@ -7,6 +7,7 @@ mod m20230803_154714_version_url;
mod m20230829_201916_country;
mod m20230914_231514_connectivity;
mod m20231011_231223_errors;
mod m20231112_142206_stats;
pub struct Migrator;
@@ -21,6 +22,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230829_201916_country::Migration),
Box::new(m20230914_231514_connectivity::Migration),
Box::new(m20231011_231223_errors::Migration),
Box::new(m20231112_142206_stats::Migration),
]
}
}
+39
View File
@@ -0,0 +1,39 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let cmd = r#"CREATE TABLE "instance_stats" (
"time" integer NOT NULL,
"host" integer NOT NULL,
"limited_accs" integer NOT NULL,
"total_accs" integer NOT NULL,
"total_requests" integer NOT NULL,
"req_photo_rail" integer NOT NULL,
"req_user_screen_name" integer NOT NULL,
"req_search" integer NOT NULL,
"req_list_tweets" integer NOT NULL,
"req_user_media" integer NOT NULL,
"req_tweet_detail" integer NOT NULL,
"req_list" integer NOT NULL,
"req_user_tweets" integer NOT NULL,
"req_user_tweets_and_replies" integer NOT NULL,
CONSTRAINT "pk_instance_stats" PRIMARY KEY ("host", "time"),
FOREIGN KEY ("host") REFERENCES "host" ("id") ON DELETE CASCADE ON UPDATE CASCADE
) WITHOUT ROWID, STRICT;"#;
let db = manager.get_connection();
db.execute_unprepared("BEGIN EXCLUSIVE").await?;
tracing::info!("adding instance_stats table..");
db.execute_unprepared(cmd).await?;
db.execute_unprepared("COMMIT TRANSACTION").await?;
db.execute_unprepared("VACUUM").await?;
Ok(())
}
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
panic!("Can't migrate down");
}
}