Skip to content

Commit 8495e72

Browse files
committed
b
1 parent 939b4ea commit 8495e72

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

plugins/magic.library/internals/SQLiteInitializer.cs

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,26 @@ public async Task Initialize(IRootResolver resolver, SqliteConnection connection
3434
await connection.OpenAsync();
3535
connection.EnableExtensions();
3636

37-
var plt = GetPlatformExtension();
38-
var extensionPath = resolver.RuntimePath("sqlite-plugins/vector" + plt);
39-
40-
// Notice, we cannot run vector_init before we've created our magic database!!
37+
// Notice, we cannot run vector_init before we've created our magic database!
4138
if (_shouldRunVectorInit)
4239
{
43-
const int maxAttempts = 3;
44-
int attempt = 0;
45-
while (true)
40+
var plt = GetPlatformExtension();
41+
var extensionPath = resolver.RuntimePath("sqlite-plugins/vector" + plt);
42+
43+
// Load the extension ONCE per connection (no retries for load).
44+
using (var load = connection.CreateCommand())
4645
{
47-
try
48-
{
49-
// Load the extension ONCE per connection (no retries for load).
50-
using (var load = connection.CreateCommand())
51-
{
52-
load.CommandText = "select load_extension($p, 'sqlite3_vector_init')";
53-
load.Parameters.AddWithValue("$p", extensionPath);
54-
_ = await load.ExecuteScalarAsync();
55-
}
56-
await RunVectorInit(connection);
57-
break;
58-
}
59-
catch (SqliteException ex) when (IsNoSuchFunctionVectorInit(ex) && ++attempt < maxAttempts)
60-
{
61-
await Task.Delay(50 * attempt);
62-
}
46+
load.CommandText = "select load_extension($p, 'sqlite3_vector_init')";
47+
load.Parameters.AddWithValue("$p", extensionPath);
48+
_ = await load.ExecuteScalarAsync();
49+
}
50+
using (var cmd = connection.CreateCommand())
51+
{
52+
cmd.CommandText = "select vector_init($tbl, $col, $opts);";
53+
cmd.Parameters.AddWithValue("$tbl", TableName);
54+
cmd.Parameters.AddWithValue("$col", ColumnName);
55+
cmd.Parameters.AddWithValue("$opts", Options);
56+
_ = await cmd.ExecuteScalarAsync();
6357
}
6458
}
6559
}
@@ -73,22 +67,6 @@ public async Task Initialize(IRootResolver resolver, SqliteConnection connection
7367
* Private helper methods.
7468
*/
7569

76-
static async Task RunVectorInit(SqliteConnection connection)
77-
{
78-
using (var cmd = connection.CreateCommand())
79-
{
80-
cmd.CommandText = "select vector_init($tbl, $col, $opts);";
81-
cmd.Parameters.AddWithValue("$tbl", TableName);
82-
cmd.Parameters.AddWithValue("$col", ColumnName);
83-
cmd.Parameters.AddWithValue("$opts", Options);
84-
_ = await cmd.ExecuteScalarAsync();
85-
}
86-
}
87-
88-
static bool IsNoSuchFunctionVectorInit(SqliteException ex) =>
89-
ex.SqliteErrorCode == 1 /* SQLITE_ERROR */ &&
90-
ex.Message?.IndexOf("no such function: vector_init", StringComparison.OrdinalIgnoreCase) >= 0;
91-
9270
static string GetPlatformExtension()
9371
{
9472
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return ".dll";

0 commit comments

Comments
 (0)