Fix sub-segment ordering: group subs after their parent in DB load

ORDER BY sequence_number put all subs (>=1000) at the end. Now groups
by parent (seq/1000), main first, then subs in order.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-19 00:25:19 +01:00
parent 9c560ccfd0
commit ba330dd208
+6 -1
View File
@@ -428,8 +428,13 @@ class ProjectDB:
data = json.loads(data) data = json.loads(data)
# Load all sequences as batch_data # Load all sequences as batch_data
# Group sub-segments (>=1000) after their parent: parent = seq_num / 1000
rows = self.conn.execute( rows = self.conn.execute(
"SELECT data FROM sequences WHERE data_file_id = ? ORDER BY sequence_number", "SELECT data FROM sequences WHERE data_file_id = ? "
"ORDER BY CASE WHEN sequence_number >= 1000 THEN sequence_number / 1000 "
"ELSE sequence_number END, "
"CASE WHEN sequence_number >= 1000 THEN 1 ELSE 0 END, "
"sequence_number",
(df["id"],), (df["id"],),
).fetchall() ).fetchall()
batch_data = [] batch_data = []