diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Core/Data/Migrations/TEMP_SeedTransfers.cs | 56 | ||||
| -rw-r--r-- | src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs | 4 |
2 files changed, 1 insertions, 59 deletions
diff --git a/src/slskd/Core/Data/Migrations/TEMP_SeedTransfers.cs b/src/slskd/Core/Data/Migrations/TEMP_SeedTransfers.cs deleted file mode 100644 index 9f973023..00000000 --- a/src/slskd/Core/Data/Migrations/TEMP_SeedTransfers.cs +++ /dev/null @@ -1,56 +0,0 @@ -// <copyright file="TransferStateMigration_04012025.cs" company="slskd Team"> -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// </copyright> - -namespace slskd.Migrations; - -using System; -using System.IO; -using Microsoft.Data.Sqlite; -using Serilog; - -public class TEMP_SeedTransfers : IMigration -{ - private ILogger Log { get; } = Serilog.Log.ForContext<TransferStateMigration_04012025>(); - - public void Apply() - { - using var connection = new SqliteConnection($"Data Source={Path.Combine(Program.DataDirectory, "transfers.db")}"); - connection.Open(); - - Log.Warning("Staring seed"); - - for (long i = 0; i < 10_000; i++) - { - string s(Guid id) => @$" - INSERT INTO Transfers (Id, Username, Direction, Filename, Size, StartOffset, State, RequestedAt, EnqueuedAt, StartedAt, EndedAt, BytesTransferred, AverageSpeed, PlaceInQueue, Removed) - VALUES ('{id}', 'Username', 'Download', 'Foo.mp3', 42, 0, 'Completed, Succeeded', '1/1/1970 0:0:0', '1/1/1970 0:0:0', '1/1/1970 0:0:0', '1/1/1970 0:0:0', 42, 0, 0, 1); - "; - - string sql = ""; - - for (int j = 0; j < 5_000; j++) - { - sql += s(Guid.NewGuid()); - } - - using var cmd = new SqliteCommand(sql, connection); - - cmd.ExecuteNonQuery(); - Log.Warning("Completed {i}", i * 5000); - } - } -} diff --git a/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs b/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs index 6d8b4cfc..7229eee4 100644 --- a/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs +++ b/src/slskd/Core/Data/Migrations/TransferStateMigration_04012025.cs @@ -48,7 +48,7 @@ public class TransferStateMigration_04012025 : IMigration { // first, check the existing database to see if the StatusDescription column exists // if it does, the migration has already been applied - var schema = Migrator.GetDatabaseSchema(ConnectionString); + var schema = SchemaInspector.GetDatabaseSchema(ConnectionString); var txfers = schema["Transfers"]; if (txfers.Any(c => c.Name == "StatusDescription")) @@ -168,8 +168,6 @@ public class TransferStateMigration_04012025 : IMigration there surely exist better ways to do this, but the reality is that 99% of the records will be "Completed, Succeeded" (48), with a few "Completed, Errored" or "Completed, Cancelled" sprinkled in. this should run in reasonable time for large collections - - todo: benchmark this against a db with a lot of transfers */ var sw = new Stopwatch(); |
