Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Analyzer/Resources/Init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ WHERE m.type = 'Material';

INSERT INTO types (id, name) VALUES (-1, 'Scene');

PRAGMA user_version = 10;
PRAGMA user_version = 11;

PRAGMA synchronous = OFF;
PRAGMA journal_mode = MEMORY;
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/AnimationClipHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
streamDataSize = 0;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertCommand?.Dispose();
Expand Down
2 changes: 1 addition & 1 deletion Analyzer/SQLite/Handlers/AssetBundleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
streamDataSize = 0;
}

public void Finalize(SqliteConnection db)
public void FinalizeDatabase(SqliteConnection db)
{
using var command = new SqliteCommand();
command.Connection = db;
Expand Down
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/AudioClipHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
name = audioClip.Name;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertCommand?.Dispose();
Expand Down
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/BuildReportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
name = buildReport.Name;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertCommand?.Dispose();
Expand Down
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/ContentSummaryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
name = string.Empty;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertSummaryCommand?.Dispose();
Expand Down
4 changes: 4 additions & 0 deletions Analyzer/SQLite/Handlers/ISQLiteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public interface ISQLiteHandler : IDisposable
{
void Init(Microsoft.Data.Sqlite.SqliteConnection db);
void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize);

// Called once after all files are processed. Indexes are created here rather than in Init so
// that bulk inserts do not have to maintain them.
void FinalizeDatabase(SqliteConnection db) { }
}

public interface ISQLiteFileParser : IDisposable
Expand Down
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/MeshHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
name = mesh.Name;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertCommand?.Dispose();
Expand Down
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/MonoScriptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
streamDataSize = 0;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertCommand?.Dispose();
Expand Down
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/PackedAssetsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
name = packedAssets.Path;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertPackedAssetsCommand?.Dispose();
Expand Down
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/PreloadDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
streamDataSize = 0;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertDepCommand?.Dispose();
Expand Down
2 changes: 1 addition & 1 deletion Analyzer/SQLite/Handlers/ShaderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private int GetKeywordId(string keyword, SqliteTransaction ctxTransaction)
return id;
}

public void Finalize(SqliteConnection db)
public void FinalizeDatabase(SqliteConnection db)
{
using var command = new SqliteCommand();
command.Connection = db;
Expand Down
4 changes: 0 additions & 4 deletions Analyzer/SQLite/Handlers/Texture2DHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
streamDataSize = texture2d.StreamDataSize;
}

public void Finalize(SqliteConnection db)
{
}

void IDisposable.Dispose()
{
m_InsertCommand?.Dispose();
Expand Down
13 changes: 10 additions & 3 deletions Analyzer/SQLite/Writers/SerializedFileSQLiteWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,23 @@ public void WriteSerializedFile(string relativePath, string fullPath, string con
}
}

// Records every referenced object that was assigned an id but never written to the objects
// table (its serialized file was not part of the analyzed input). Must run after all files are
// Lets the handlers create their indexes, then records every referenced object that was assigned
// an id but never written to the objects table (its serialized file was not part of the analyzed
// input). Must run after all files are
// processed, since an id is only known to be dangling once nothing has claimed it as an object.
// The set of written objects/files is read back from the database so this is robust to every
// object write site (regular objects, synthetic Scene objects, etc.) without instrumenting them.
public void FinalizeDatabase()
{
if (!m_Initialized)
return;

foreach (var handler in m_Handlers.Values)
handler.FinalizeDatabase(m_Database);

// Dangling refs are part of reference tracking, so honor --skip-references (the view that
// makes them useful joins the refs table, which is empty in that mode anyway).
if (!m_Initialized || m_SkipReferences)
if (m_SkipReferences)
return;

var writtenObjectIds = ReadIntSet("SELECT id FROM objects");
Expand Down
1 change: 1 addition & 0 deletions Documentation/analyzer-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ Any schema change - a new or changed table, view or column - must bump the pragm
| 8 | `archives.name` is the path relative to the scanned directory, not the bare file name ([#149](https://github.com/Unity-Technologies/UnityDataTools/issues/149)) |
| 9 | `content_layout*` tables track the version 3 layout schema of Unity 6.7: loadables keyed by `loadable_index`, `stable_id` / `artifact_index` columns replace `cfid` / `content_hash`, `is_root_asset` records the root position, and the v2-only columns (`asset_path`, `source_lfid`) exist only in databases imported from a version 2 layout ([#131](https://github.com/Unity-Technologies/UnityDataTools/issues/131)) |
| 10 | Added the `managed_references` table, `managed_reference_view` and `managed_reference_stats_view` ([#53](https://github.com/Unity-Technologies/UnityDataTools/issues/53)) |
| 11 | Added indexes on `preload_dependencies(object)`, `preload_dependencies(dependency)`, `shader_subprograms(shader)` and `shader_subprogram_keywords(subprogram_id)` ([#83](https://github.com/Unity-Technologies/UnityDataTools/issues/83)) |

## Related documentation

Expand Down
18 changes: 18 additions & 0 deletions UnityDataTool.Tests/UnityDataToolAssetBundleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,24 @@ public async Task Analyze_MonoScripts_DatabaseContainsExpectedContent()
"Expected to find exactly one MonoBehaviour instance of SerializeReferencePolymorphismExample");
}

[Test]
public async Task Analyze_HandlerIndexes_AreCreated(
[Values("", "--skip-references")] string options)
{
var databasePath = SQLTestHelper.GetDatabasePath(m_TestOutputFolder);
var analyzePath = Path.Combine(Context.UnityDataFolder);

Assert.AreEqual(0, await Program.Main(new string[] { "analyze", analyzePath }.Concat(options.Split(" ", StringSplitOptions.RemoveEmptyEntries)).ToArray()));

using var db = SQLTestHelper.OpenDatabase(databasePath);
SQLTestHelper.AssertQueryInt(db,
@"SELECT COUNT(*) FROM sqlite_master WHERE type = 'index' AND name IN (
'preload_dependencies_object', 'preload_dependencies_dependency',
'shader_subprograms_shader_index', 'shader_subprogram_keywords_subprogram_id_index')",
4,
"Expected the indexes created by the handlers");
}

// The 2019.4 and 2020.3 bundles have a version 1 registry, where the rid is the entry's position;
// the later ones have version 2. The instance data is the same in both.
[Test]
Expand Down
Loading