mirror of
https://github.com/encounter/decomp.dev.git
synced 2026-07-10 03:18:48 -07:00
Allow duplicate units within a report
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
PRAGMA foreign_keys = off;
|
||||
|
||||
ALTER TABLE report_report_units
|
||||
RENAME TO report_report_units_old;
|
||||
|
||||
CREATE TABLE report_report_units
|
||||
(
|
||||
report_id INTEGER NOT NULL,
|
||||
report_unit_id BLOB NOT NULL,
|
||||
unit_index INTEGER NOT NULL, -- Index of the report unit in the report
|
||||
PRIMARY KEY (report_id, report_unit_id, unit_index),
|
||||
FOREIGN KEY (report_id) REFERENCES reports (id),
|
||||
FOREIGN KEY (report_unit_id) REFERENCES report_units (id)
|
||||
);
|
||||
|
||||
DROP INDEX report_report_units_report_id_index;
|
||||
DROP INDEX report_report_units_report_unit_id_index;
|
||||
|
||||
CREATE INDEX report_report_units_report_id_index ON report_report_units (report_id);
|
||||
CREATE INDEX report_report_units_report_unit_id_index ON report_report_units (report_unit_id);
|
||||
|
||||
INSERT INTO report_report_units
|
||||
SELECT *
|
||||
FROM report_report_units_old;
|
||||
|
||||
DROP TABLE report_report_units_old;
|
||||
|
||||
PRAGMA foreign_keys = on;
|
||||
+2
-2
@@ -223,13 +223,13 @@ impl Database {
|
||||
{
|
||||
let idx = row.unit_index as usize;
|
||||
if idx != report.units.len() {
|
||||
bail!("Report unit index mismatch");
|
||||
bail!("Report unit index mismatch: {} but expected {}", idx, report.units.len());
|
||||
}
|
||||
let key: UnitKey = row.id.as_slice().try_into()?;
|
||||
let data = decompress(&row.data).context("Failed to decompress report unit data")?;
|
||||
let hash: UnitKey = blake3::hash(data.as_ref()).into();
|
||||
if hash != key {
|
||||
bail!("Report unit data hash mismatch");
|
||||
bail!("Report unit data hash mismatch for unit {}", idx);
|
||||
}
|
||||
let unit = ReportUnit::decode(data.as_ref()).context("Failed to decode report unit")?;
|
||||
report.units.push(unit);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{sync::Arc, time::Instant};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use anyhow::{anyhow, Context};
|
||||
use axum::{
|
||||
extract::{Query, State},
|
||||
http::StatusCode,
|
||||
@@ -88,7 +88,13 @@ pub async fn get_projects(
|
||||
let report = state
|
||||
.db
|
||||
.get_report(&info.project.owner, &info.project.repo, &info.commit.sha, version)
|
||||
.await;
|
||||
.await
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to fetch report for {}/{} sha {} version {}",
|
||||
info.project.owner, info.project.repo, info.commit.sha, version
|
||||
)
|
||||
});
|
||||
(info, report)
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user