From 2f933ffc9c83b670e41909c0a127b483a51aef47 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 23 Jan 2021 00:11:31 -0500 Subject: [PATCH] added index --- .../DataAccessLayers/DbInitializerPostgresDal.cs | 4 ++++ .../Tools/PostgresTools.cs | 15 ++++----------- .../DbInitializerPostgresDalTests.cs | 6 +++++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/DbInitializerPostgresDal.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/DbInitializerPostgresDal.cs index a50e05b..fd4b703 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/DbInitializerPostgresDal.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/DbInitializerPostgresDal.cs @@ -141,6 +141,10 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers { var addLastSync = $@"ALTER TABLE {_settings.TwitterUserTableName} ADD lastSync TIMESTAMP (2) WITHOUT TIME ZONE"; await _tools.ExecuteRequestAsync(addLastSync); + + var addIndex = $@"CREATE INDEX IF NOT EXISTS lastsync_twitteruser ON {_settings.TwitterUserTableName}(lastSync)"; + await _tools.ExecuteRequestAsync(addIndex); + return new Version(2, 0); } diff --git a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/Tools/PostgresTools.cs b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/Tools/PostgresTools.cs index 223b1ea..32a379f 100644 --- a/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/Tools/PostgresTools.cs +++ b/src/DataAccessLayers/BirdsiteLive.DAL.Postgres/Tools/PostgresTools.cs @@ -18,18 +18,11 @@ namespace BirdsiteLive.DAL.Postgres.Tools public async Task ExecuteRequestAsync(string request) { - try + using (var conn = new NpgsqlConnection(_settings.ConnString)) + using (var cmd = new NpgsqlCommand(request, conn)) { - using (var conn = new NpgsqlConnection(_settings.ConnString)) - using (var cmd = new NpgsqlCommand(request, conn)) - { - await conn.OpenAsync(); - await cmd.ExecuteNonQueryAsync(); - } - } - catch (Exception e) - { - Console.WriteLine(e); + await conn.OpenAsync(); + await cmd.ExecuteNonQueryAsync(); } } } diff --git a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/DbInitializerPostgresDalTests.cs b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/DbInitializerPostgresDalTests.cs index 9cd59a3..a186dc3 100644 --- a/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/DbInitializerPostgresDalTests.cs +++ b/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/DbInitializerPostgresDalTests.cs @@ -13,7 +13,11 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers public async Task CleanUp() { var dal = new DbInitializerPostgresDal(_settings, _tools); - await dal.DeleteAllAsync(); + try + { + await dal.DeleteAllAsync(); + } + catch (Exception ) { } } [TestMethod]