Skip to content

Commit

Permalink
Issue/458 (#459)
Browse files Browse the repository at this point in the history
* (maint) Change log level

* (#458) Add more logging
  • Loading branch information
jibedoubleve authored Jan 9, 2024
1 parent 75a0f2f commit 29a779b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/Lanceur.Infra.SQLite/DbActions/AliasDbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@ public AliasDbAction(IDbConnectionManager db, ILoggerFactory logFactory)

#region Methods

private static void CreateAdditionalParameters(long idAlias, IEnumerable<QueryResultAdditionalParameters> parameters, IDbTransaction tx)
private void CreateAdditionalParameters(long idAlias, IEnumerable<QueryResultAdditionalParameters> parameters, IDbTransaction tx)
{
using var _ = _logger.BeginSingleScope("Parameters", parameters);
const string sql1 = "delete from alias_argument where id_alias = @idAlias";
const string sql2 = "insert into alias_argument (id_alias, argument, name) values(@idAlias, @parameter, @name);";

// Remove existing additional alias parameters
tx.Connection.Execute(sql1, new { idAlias });
var deletedRowsCount = tx.Connection.Execute(sql1, new { idAlias });

// Create alias additional parameters
tx.Connection.Execute(sql2, parameters.ToEntity(idAlias));
var addedRowsCount = tx.Connection.Execute(sql2, parameters.ToEntity(idAlias));

if (deletedRowsCount > 0 && addedRowsCount == 0)
{
_logger.LogWarning("Deleting {DeletedRowsCount} parameters while adding no new parameters", deletedRowsCount);
}
}

private static void CreateAdditionalParameters(AliasQueryResult alias, IDbTransaction tx)
private void CreateAdditionalParameters(AliasQueryResult alias, IDbTransaction tx)
=> CreateAdditionalParameters(alias.Id, alias.AdditionalParameters, tx);

private static void UpdateName(AliasQueryResult alias, IDbTransaction tx)
Expand Down
11 changes: 8 additions & 3 deletions src/Lanceur.Infra.SQLite/Entities/AdditionalParameterMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ public static class AdditionalParameterMixin
#region Methods

public static IEnumerable<AdditionalParameter>
ToEntity(this IEnumerable<QueryResultAdditionalParameters> collection, long idAlias) => collection
.Select(item => new AdditionalParameter { Id = item.Id, IdAlias = idAlias, Name = item.Name, Parameter = item.Parameter })
.ToList();
ToEntity(this IEnumerable<QueryResultAdditionalParameters> collection, long idAlias) => collection.Select(
item => new AdditionalParameter
{
Id = item.Id,
IdAlias = idAlias,
Name = item.Name,
Parameter = item.Parameter
}).ToList();

#endregion Methods
}
2 changes: 1 addition & 1 deletion src/Lanceur.Infra.SQLite/SqliteRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public void SetUsage(QueryResult alias)
_setUsageDbAction.SetUsage(ref alias, idSession);

if (alias is AliasQueryResult aqr) { _aliasDbAction.Update(aqr); }
else _logger.LogWarning("Alias {AliasName} is not an AliasQueryResult", alias.Name);
else _logger.LogInformation("Alias {AliasName} is not an AliasQueryResult", alias.Name);
}

public void SetUsage(string aliasName) => SetUsage(new AliasQueryResult() { Name = aliasName });
Expand Down

0 comments on commit 29a779b

Please sign in to comment.