E2: misure del filtro Copie, migrazione 0004 e prove di web e Docker

Il filtro «Copie» con 200.000 elementi stava al limite dei 250 ms
(«Copiati» 249 ms): la migrazione 0004 aggiunge solo l'indice
ix_media_sha256_entry e la finestra scende a 160 ms. Totali e giorni
contano «Copiati» partendo dalle copie e gli altri valori con un solo
passaggio sui file dietro gli elenchi degli SHA-256 copiati (1,5 s ->
0,7 s); hanno un limite loro di 3 s, scritto in decisioni.md con le
misure.

«Copia di nuovo» sceglie un file dell'account che è sul disco: prima
prendeva il primo con quello SHA-256 e, nella demo, a certe ore non
scriveva nulla.

Nuove prove: API delle copie, coerenza della demo, interfaccia nel
browser, opzioni del server, avvio del contenitore con /esporta,
contenuto dell'immagine e modelli, migrazione 4 e scala.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 15:29:59 +01:00
1 parent 736d241a38
commit 724db13e1b
14 files changed
+1403 -38

No files matched your search

+55 -2
View File
@@ -164,6 +164,9 @@ public sealed class MigrationTests
[TestMethod]
public async Task DatabaseAtVersion2IsUpgradedWithForeignKeysClean() => await UpgradeKeepsEverything(2);
[TestMethod]
public async Task DatabaseAtVersion3IsUpgradedWithForeignKeysClean() => await UpgradeKeepsEverything(3);
[TestMethod]
public void MigrationThreeChangesNoExistingTable()
{
@@ -174,12 +177,42 @@ public sealed class MigrationTests
var before = SchemaOf(path, Version1Tables);
var shapesBefore = TableShapes(path, Version1Tables);
Close(FebeDatabase.Open(path, all));
// Migration 4 adds an index on media (the «Copie» filter): migration 3 alone is compared here.
Close(FebeDatabase.Open(path, all.Take(3).ToList()));
CollectionAssert.AreEqual(before, SchemaOf(path, Version1Tables), "la migrazione 3 non tocca tabelle né indici esistenti");
CollectionAssert.AreEqual(shapesBefore, TableShapes(path, Version1Tables), "colonne e indici delle tabelle esistenti restano gli stessi");
}
/// <summary>
/// Migration 4 (tappa E2) adds only the index of the «Copie» filter on media (sha256, entry_id): every other table,
/// column and index stays the same, and the plan of the list of the entries with a copy reads it.
/// </summary>
[TestMethod]
public void MigrationFourOnlyAddsTheIndexOfTheCopiesFilter()
{
using var temp = new TempFolder();
var path = temp.Combine("dati", FebeDatabase.FileName);
var all = MigrationRunner.LoadEmbedded();
Assert.IsGreaterThanOrEqualTo(4, all.Count);
Close(FebeDatabase.Open(path, all.Take(3).ToList()));
var tables = TablesOf(path);
var before = SchemaOf(path, tables);
Close(FebeDatabase.Open(path, all.Take(4).ToList()));
CollectionAssert.AreEqual(tables, TablesOf(path), "nessuna tabella nuova");
var added = SchemaOf(path, tables).Except(before).ToList();
Assert.HasCount(1, added, string.Join(" | ", added));
StringAssert.Contains(added[0], "ix_media_sha256_entry");
StringAssert.Contains(added[0], "(sha256, entry_id) WHERE sha256 IS NOT NULL");
CollectionAssert.IsSubsetOf(before, SchemaOf(path, tables), "nulla di prima cambia");
using var connection = Connect(path);
var plan = string.Join(" | ", ReadColumn(connection,
"EXPLAIN QUERY PLAN SELECT m2.entry_id FROM export_copy c JOIN media m2 ON m2.sha256 = c.source_sha256 WHERE c.destination_id IN (1, 2) AND c.state = 'Copied'", 3));
StringAssert.Contains(plan, "COVERING INDEX ix_media_sha256_entry", plan);
}
[TestMethod]
public async Task DatabaseOneVersionNewerIsRefusedAndLeftUntouched()
{
@@ -218,7 +251,7 @@ public sealed class MigrationTests
await using (var db = FebeDatabase.Open(path, all))
{
Assert.AreEqual(all.Count, db.SchemaVersion);
Assert.AreEqual(3, db.SchemaVersion);
Assert.AreEqual(4, db.SchemaVersion);
}
using var connection = Connect(path);
@@ -340,6 +373,26 @@ public sealed class MigrationTests
return rows;
}
/// <summary>Every table of the database, by name.</summary>
private static List<string> TablesOf(string path)
{
using var connection = Connect(path);
return ReadColumn(connection, "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name", 0);
}
/// <summary>One column of every row of a query, as text.</summary>
private static List<string> ReadColumn(SqliteConnection connection, string sql, int column)
{
using var r = connection.Command(sql).ExecuteReader();
var values = new List<string>();
while (r.Read())
{
values.Add(Convert.ToString(r.GetValue(column), System.Globalization.CultureInfo.InvariantCulture) ?? string.Empty);
}
return values;
}
/// <summary>The SQL of the tables and of their indexes and triggers.</summary>
private static List<string> SchemaOf(string path, IEnumerable<string> tables)
{