Include cells with plugin data
This commit is contained in:
parent
7552573d00
commit
c9dcd3b7c5
@ -25,7 +25,8 @@ pub async fn dump_plugin_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str) -> R
|
||||
let page_size = 20;
|
||||
let mut last_id = None;
|
||||
loop {
|
||||
let plugins = plugin::batched_get_with_file_and_mod(&pool, page_size, last_id).await?;
|
||||
let plugins =
|
||||
plugin::batched_get_with_data(&pool, page_size, last_id, "Skyrim.esm", 1).await?;
|
||||
if plugins.is_empty() {
|
||||
break;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ pub struct UnsavedPlugin<'a> {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, FromRow)]
|
||||
pub struct PluginWithFileAndMod {
|
||||
pub struct PluginWithData {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub hash: i64,
|
||||
@ -55,6 +55,7 @@ pub struct PluginWithFileAndMod {
|
||||
pub created_at: NaiveDateTime,
|
||||
pub file: Option<serde_json::Value>,
|
||||
pub r#mod: Option<serde_json::Value>,
|
||||
pub cells: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
@ -89,29 +90,36 @@ pub async fn insert<'a>(
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(pool))]
|
||||
pub async fn batched_get_with_file_and_mod(
|
||||
pub async fn batched_get_with_data(
|
||||
pool: &sqlx::Pool<sqlx::Postgres>,
|
||||
page_size: i64,
|
||||
last_id: Option<i32>,
|
||||
) -> Result<Vec<PluginWithFileAndMod>> {
|
||||
master: &str,
|
||||
world_id: i32,
|
||||
) -> Result<Vec<PluginWithData>> {
|
||||
let last_id = last_id.unwrap_or(0);
|
||||
sqlx::query_as!(
|
||||
PluginWithFileAndMod,
|
||||
PluginWithData,
|
||||
"SELECT
|
||||
plugins.*,
|
||||
json_agg(files.*) as file,
|
||||
json_agg(mods.*) as mod
|
||||
json_agg(DISTINCT files.*) as file,
|
||||
json_agg(DISTINCT mods.*) as mod,
|
||||
COALESCE(json_agg(DISTINCT jsonb_build_object('x', cells.x, 'y', cells.y)) FILTER (WHERE cells.x IS NOT NULL AND cells.y IS NOT NULL AND cells.master = $3 AND cells.world_id = $4), '[]') AS cells
|
||||
FROM plugins
|
||||
LEFT OUTER JOIN files ON files.id = plugins.file_id
|
||||
LEFT OUTER JOIN mods ON mods.id = files.mod_id
|
||||
LEFT OUTER JOIN plugin_cells ON plugin_cells.plugin_id = plugins.id
|
||||
LEFT OUTER JOIN cells ON cells.id = plugin_cells.cell_id
|
||||
WHERE plugins.id > $2
|
||||
GROUP BY plugins.id
|
||||
ORDER BY plugins.id ASC
|
||||
LIMIT $1",
|
||||
page_size,
|
||||
last_id
|
||||
last_id,
|
||||
master,
|
||||
world_id
|
||||
)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
.context("Failed to batch get with cells")
|
||||
.context("Failed to batch get with data")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user