Log spans, track size & undownloadable files
This commit is contained in:
@@ -15,7 +15,7 @@ pub struct Cell {
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn insert_cell(
|
||||
pub async fn insert(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
form_id: i32,
|
||||
x: Option<i32>,
|
||||
|
||||
@@ -13,13 +13,15 @@ pub struct File {
|
||||
pub category: Option<String>,
|
||||
pub version: Option<String>,
|
||||
pub mod_version: Option<String>,
|
||||
pub size: i64,
|
||||
pub uploaded_at: NaiveDateTime,
|
||||
pub has_download_link: bool,
|
||||
pub updated_at: NaiveDateTime,
|
||||
pub created_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn insert_file(
|
||||
pub async fn insert(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
name: &str,
|
||||
file_name: &str,
|
||||
@@ -28,13 +30,14 @@ pub async fn insert_file(
|
||||
category: Option<&str>,
|
||||
version: Option<&str>,
|
||||
mod_version: Option<&str>,
|
||||
size: i64,
|
||||
uploaded_at: NaiveDateTime,
|
||||
) -> Result<File> {
|
||||
sqlx::query_as!(
|
||||
File,
|
||||
"INSERT INTO files
|
||||
(name, file_name, nexus_file_id, mod_id, category, version, mod_version, uploaded_at, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, now(), now())
|
||||
(name, file_name, nexus_file_id, mod_id, category, version, mod_version, size, uploaded_at, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, now(), now())
|
||||
ON CONFLICT (mod_id, nexus_file_id) DO UPDATE
|
||||
SET (name, file_name, category, version, mod_version, uploaded_at, updated_at) =
|
||||
(EXCLUDED.name, EXCLUDED.file_name, EXCLUDED.category, EXCLUDED.version, EXCLUDED.mod_version, EXCLUDED.uploaded_at, now())
|
||||
@@ -46,9 +49,30 @@ pub async fn insert_file(
|
||||
category,
|
||||
version,
|
||||
mod_version,
|
||||
size,
|
||||
uploaded_at
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.context("Failed to insert file")
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn update_has_download_link(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
id: i32,
|
||||
has_download_link: bool,
|
||||
) -> Result<File> {
|
||||
sqlx::query_as!(
|
||||
File,
|
||||
"UPDATE files
|
||||
SET has_download_link = $2
|
||||
WHERE id = $1
|
||||
RETURNING *",
|
||||
id,
|
||||
has_download_link,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.context("Failed to update file")
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct Game {
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn insert_game(
|
||||
pub async fn insert(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
name: &str,
|
||||
nexus_game_id: i32,
|
||||
|
||||
@@ -17,7 +17,7 @@ pub struct Mod {
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn get_mod_by_nexus_mod_id(
|
||||
pub async fn get_by_nexus_mod_id(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
nexus_mod_id: i32,
|
||||
) -> Result<Option<Mod>> {
|
||||
@@ -32,7 +32,7 @@ pub async fn get_mod_by_nexus_mod_id(
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn insert_mod(
|
||||
pub async fn insert(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
name: &str,
|
||||
nexus_mod_id: i32,
|
||||
|
||||
@@ -10,6 +10,7 @@ pub struct Plugin {
|
||||
pub hash: i64,
|
||||
pub file_id: i32,
|
||||
pub version: Option<f64>,
|
||||
pub size: i64,
|
||||
pub author: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub masters: Option<Vec<String>>,
|
||||
@@ -18,12 +19,13 @@ pub struct Plugin {
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn insert_plugin(
|
||||
pub async fn insert(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
name: &str,
|
||||
hash: i64,
|
||||
file_id: i32,
|
||||
version: Option<f64>,
|
||||
size: i64,
|
||||
author: Option<&str>,
|
||||
description: Option<&str>,
|
||||
masters: Option<&[String]>,
|
||||
@@ -31,8 +33,8 @@ pub async fn insert_plugin(
|
||||
sqlx::query_as!(
|
||||
Plugin,
|
||||
"INSERT INTO plugins
|
||||
(name, hash, file_id, version, author, description, masters, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, now(), now())
|
||||
(name, hash, file_id, version, size, author, description, masters, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, now(), now())
|
||||
ON CONFLICT (file_id, name) DO UPDATE
|
||||
SET (hash, version, author, description, masters, updated_at) =
|
||||
(EXCLUDED.hash, EXCLUDED.version, EXCLUDED.author, EXCLUDED.description, EXCLUDED.masters, now())
|
||||
@@ -41,6 +43,7 @@ pub async fn insert_plugin(
|
||||
hash,
|
||||
file_id,
|
||||
version,
|
||||
size,
|
||||
author,
|
||||
description,
|
||||
masters
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct PluginCell {
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn insert_plugin_cell(
|
||||
pub async fn insert(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
plugin_id: i32,
|
||||
cell_id: i32,
|
||||
|
||||
Reference in New Issue
Block a user