some cleanups

This commit is contained in:
Vincent Cloutier 2022-12-30 12:28:48 -05:00
parent 1d25822919
commit def5649097
3 changed files with 11 additions and 43 deletions

View file

@ -6,19 +6,28 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers.Base
public class PostgresBase
{
protected readonly PostgresSettings _settings;
protected NpgsqlDataSource _dataSource;
#region Ctor
protected PostgresBase(PostgresSettings settings)
{
_settings = settings;
_dataSource = NpgsqlDataSource.Create(settings.ConnString);
}
#endregion
protected NpgsqlDataSource DataSource
{
get
{
return _dataSource;
}
}
protected NpgsqlConnection Connection
{
get
{
return new NpgsqlConnection(_settings.ConnString);
return _dataSource.CreateConnection();
}
}
}

View file

@ -32,8 +32,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.ExecuteAsync(
$"INSERT INTO {_settings.FollowersTableName} (acct,host,inboxRoute,sharedInboxRoute,followings,followingsSyncStatus,actorId) VALUES(@acct,@host,@inboxRoute,@sharedInboxRoute,@followings,CAST(@followingsSyncStatus as json),@actorId)",
new { acct, host, inboxRoute, sharedInboxRoute, followings, followingsSyncStatus = serializedDic, actorId });
@ -46,8 +44,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = (await dbConnection.QueryAsync<int>(query)).FirstOrDefault();
return result;
}
@ -59,8 +55,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = (await dbConnection.QueryAsync<int>(query)).FirstOrDefault();
return result;
}
@ -75,8 +69,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = (await dbConnection.QueryAsync<SerializedFollower>(query, new { acct, host })).FirstOrDefault();
return Convert(result);
}
@ -90,8 +82,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = await dbConnection.QueryAsync<SerializedFollower>(query, new { id = followedUserId});
return result.Select(Convert).ToArray();
}
@ -103,8 +93,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = await dbConnection.QueryAsync<SerializedFollower>(query);
return result.Select(Convert).ToArray();
}
@ -120,8 +108,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { follower.Id, follower.Followings, followingsSyncStatus = serializedDic, postingErrorCount = follower.PostingErrorCount });
}
}
@ -134,8 +120,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { id });
}
}
@ -152,8 +136,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { acct, host });
}
}

View file

@ -6,6 +6,7 @@ using BirdsiteLive.DAL.Models;
using BirdsiteLive.DAL.Postgres.DataAccessLayers.Base;
using BirdsiteLive.DAL.Postgres.Settings;
using Dapper;
using Npgsql;
namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
{
@ -24,8 +25,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.ExecuteAsync(
$"INSERT INTO {_settings.TwitterUserTableName} (acct,lastTweetPostedId,lastTweetSynchronizedForAllFollowersId) VALUES(@acct,@lastTweetPostedId,@lastTweetSynchronizedForAllFollowersId)",
new { acct, lastTweetPostedId, lastTweetSynchronizedForAllFollowersId = lastTweetPostedId });
@ -40,8 +39,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = (await dbConnection.QueryAsync<SyncTwitterUser>(query, new { acct })).FirstOrDefault();
return result;
}
@ -53,8 +50,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = (await dbConnection.QueryAsync<SyncTwitterUser>(query, new { id })).FirstOrDefault();
return result;
}
@ -66,8 +61,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = (await dbConnection.QueryAsync<int>(query)).FirstOrDefault();
return result;
}
@ -79,8 +72,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = (await dbConnection.QueryAsync<int>(query)).FirstOrDefault();
return result;
}
@ -92,8 +83,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = await dbConnection.QueryAsync<SyncTwitterUser>(query, new { maxNumber });
return result.ToArray();
}
@ -105,8 +94,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = await dbConnection.QueryAsync<SyncTwitterUser>(query, new { maxNumber });
return result.ToArray();
}
@ -118,8 +105,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
var result = await dbConnection.QueryAsync<SyncTwitterUser>(query);
return result.ToArray();
}
@ -134,8 +119,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { username, twitterUserId });
}
}
@ -150,8 +133,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { id, lastTweetPostedId, lastTweetSynchronizedForAllFollowersId, fetchingErrorCount, lastSync = lastSync.ToUniversalTime() });
}
}
@ -171,8 +152,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { acct });
}
}
@ -185,8 +164,6 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { id });
}
}