Skip to content

Commit 8ad05d2

Browse files
[#55] Address review: dedup type inserts, clarify comments, doc fixes
- PackedAssetsHandler: skip redundant type inserts via a HashSet (a report can list thousands of objects sharing a few types). - AddType: reword the OR IGNORE comment - first insert wins is fine since the name for a given id matches across TypeIdRegistry and TypeTree; the case that matters (id missing from the registry) still gets its name from TypeTree. - buildreport.md: capitalization and spacing.
1 parent 93892f6 commit 8ad05d2

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

Analyzer/SQLite/Commands/SerializedFile/AddType.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ internal class AddType : AbstractCommand
1919
protected override string DDLSource => null;
2020

2121
// The BuildReport PackedAssetsHandler may have already inserted a type by numeric id (with a
22-
// name from TypeIdRegistry). The TypeTree name here is authoritative and identical for known
23-
// ids, so ignore the conflict rather than crashing when both a report and its build output
24-
// are analyzed together.
22+
// name from TypeIdRegistry), so ignore the conflict rather than crashing when both a report
23+
// and its build output are analyzed together. First insert wins: the name for a given id is
24+
// the same whether it comes from TypeIdRegistry or the TypeTree, so it does not matter which
25+
// path runs first (a mismatch would indicate a deeper problem). The case that matters is a
26+
// type missing from TypeIdRegistry (e.g. an older UnityDataTool reading a newer file); the
27+
// handler skips those, so the name still arrives here from TypeTree analysis.
2528
protected override string ConflictClause => "OR IGNORE";
2629

2730
protected override Dictionary<string, SqliteType> Fields => new()

Analyzer/SQLite/Handlers/PackedAssetsHandler.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public class PackedAssetsHandler : ISQLiteHandler
1616
private SqliteCommand m_InsertTypeCommand;
1717
private Dictionary<(string guid, string path), long> m_SourceAssetCache = new();
1818

19+
// Type ids we have already tried to add to the types table. A single BuildReport can list
20+
// thousands of objects sharing a handful of types, so this skips the redundant INSERT calls.
21+
// The handler instance lives for the whole analyze, so this dedups across all reports.
22+
private HashSet<int> m_InsertedTypes = new();
23+
1924
public void Init(SqliteConnection db)
2025
{
2126
using var command = db.CreateCommand();
@@ -106,7 +111,8 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
106111

107112
// Populate the types table so views can display the type name even when the build
108113
// output (and its TypeTrees) is not analyzed alongside the report.
109-
if (TypeIdRegistry.TryGetTypeName(content.Type, out var typeName))
114+
if (m_InsertedTypes.Add(content.Type) &&
115+
TypeIdRegistry.TryGetTypeName(content.Type, out var typeName))
110116
{
111117
m_InsertTypeCommand.Transaction = ctx.Transaction;
112118
m_InsertTypeCommand.Parameters["@id"].Value = content.Type;

Documentation/buildreport.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ For consistency and clarity, database columns use slightly different names than
262262

263263
## Limitations
264264

265-
**Duplicate filenames:** Multiple build reports cannot be imported into the same database if they share the same filename. This is a general UnityDataTool limitation that assumes unique SerializedFile names. The BuildReport files in the build history (introduced in Unity 6.6) intentionally have unique file names (incorporating the build session GUID), so analyze does not hit this issue when analyzing multiple entries from the BuildHistory folder. When analyzing multiple AssetBundle build reports, or build reports from older versions of unity, be sure to assign a unique filename to each. See also issue #36.
265+
**Duplicate filenames:** Multiple build reports cannot be imported into the same database if they share the same filename. This is a general UnityDataTool limitation that assumes unique SerializedFile names. The BuildReport files in the build history (introduced in Unity 6.6) intentionally have unique file names (incorporating the build session GUID), so analyze does not hit this issue when analyzing multiple entries from the BuildHistory folder. When analyzing multiple AssetBundle build reports, or build reports from older versions of Unity, be sure to assign a unique filename to each. See also issue #36.
266266

267267
### Information Not Exported
268268

0 commit comments

Comments
 (0)