Renaming a person keeps the chart and its analyses
The person edit form sent the birth data with every save, so a new name alone
recalculated the chart, deleted its analyses and comparisons and queued a new
summary. Now the backend ignores birth data equal to the stored one (and keeps
everything when a recalculation gives the same chart), and the form sends it
only when it changed. The name can be changed after the correction window too
("Átnevezés" on the person card).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -267,15 +267,25 @@ pub async fn update(
|
||||
None => chart.label.clone(),
|
||||
};
|
||||
let is_primary = req.is_primary.unwrap_or(chart.is_primary);
|
||||
let recalculated = match req.birth {
|
||||
// The same birth data again (e.g. only the name changed): no recalculation,
|
||||
// and the analyses and comparisons stay. A new calculation that gives the
|
||||
// same chart keeps them too.
|
||||
let birth = req.birth.map(clean_birth).transpose()?.filter(|b| *b != chart.birth_data);
|
||||
let recalculated = match birth {
|
||||
Some(birth) => Some(corrected_birth(&state, &auth, &chart, birth).await?),
|
||||
None => None,
|
||||
};
|
||||
let chart_changed = recalculated.as_ref().is_some_and(|(_, _, hash)| *hash != chart.chart_hash);
|
||||
let mut tx = state.db.begin().await?;
|
||||
if let Some((birth, result, hash)) = &recalculated {
|
||||
// The old summary, the comparisons (and an admin's analyses) no longer match the chart.
|
||||
sqlx::query("DELETE FROM analyses WHERE chart_id = $1").bind(id).execute(&mut *tx).await?;
|
||||
sqlx::query("DELETE FROM synastries WHERE chart1_id = $1 OR chart2_id = $1").bind(id).execute(&mut *tx).await?;
|
||||
if chart_changed {
|
||||
// The old summary, the comparisons (and an admin's analyses) no longer match the chart.
|
||||
sqlx::query("DELETE FROM analyses WHERE chart_id = $1").bind(id).execute(&mut *tx).await?;
|
||||
sqlx::query("DELETE FROM synastries WHERE chart1_id = $1 OR chart2_id = $1")
|
||||
.bind(id)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
}
|
||||
sqlx::query("UPDATE charts SET birth_data = $1, result = $2, chart_hash = $3 WHERE id = $4")
|
||||
.bind(birth)
|
||||
.bind(result)
|
||||
@@ -303,7 +313,7 @@ pub async fn update(
|
||||
birth_changes::record(&mut tx, &auth, id).await?;
|
||||
}
|
||||
tx.commit().await?;
|
||||
if recalculated.is_some() {
|
||||
if chart_changed {
|
||||
queue_summary(&state, &auth, &row).await;
|
||||
}
|
||||
Ok(Json(row.owner_view()))
|
||||
|
||||
Reference in New Issue
Block a user