|
@@ -34,7 +34,7 @@ namespace Emby.Server.Implementations.Activity
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- Logger.LogError("Error loading database file. Will reset and retry.", ex);
|
|
|
+ Logger.LogError(ex, "Error loading database file. Will reset and retry.");
|
|
|
|
|
|
FileSystem.DeleteFile(DbFilePath);
|
|
|
|
|
@@ -73,7 +73,7 @@ namespace Emby.Server.Implementations.Activity
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- Logger.LogError("Error migrating activity log database", ex);
|
|
|
+ Logger.LogError(ex, "Error migrating activity log database");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -87,36 +87,34 @@ namespace Emby.Server.Implementations.Activity
|
|
|
}
|
|
|
|
|
|
using (WriteLock.Write())
|
|
|
+ using (var connection = CreateConnection())
|
|
|
{
|
|
|
- using (var connection = CreateConnection())
|
|
|
+ connection.RunInTransaction(db =>
|
|
|
{
|
|
|
- connection.RunInTransaction(db =>
|
|
|
+ using (var statement = db.PrepareStatement("insert into ActivityLog (Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)"))
|
|
|
{
|
|
|
- using (var statement = db.PrepareStatement("insert into ActivityLog (Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)"))
|
|
|
+ statement.TryBind("@Name", entry.Name);
|
|
|
+
|
|
|
+ statement.TryBind("@Overview", entry.Overview);
|
|
|
+ statement.TryBind("@ShortOverview", entry.ShortOverview);
|
|
|
+ statement.TryBind("@Type", entry.Type);
|
|
|
+ statement.TryBind("@ItemId", entry.ItemId);
|
|
|
+
|
|
|
+ if (entry.UserId.Equals(Guid.Empty))
|
|
|
{
|
|
|
- statement.TryBind("@Name", entry.Name);
|
|
|
-
|
|
|
- statement.TryBind("@Overview", entry.Overview);
|
|
|
- statement.TryBind("@ShortOverview", entry.ShortOverview);
|
|
|
- statement.TryBind("@Type", entry.Type);
|
|
|
- statement.TryBind("@ItemId", entry.ItemId);
|
|
|
-
|
|
|
- if (entry.UserId.Equals(Guid.Empty))
|
|
|
- {
|
|
|
- statement.TryBindNull("@UserId");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- statement.TryBind("@UserId", entry.UserId.ToString("N"));
|
|
|
- }
|
|
|
-
|
|
|
- statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue());
|
|
|
- statement.TryBind("@LogSeverity", entry.Severity.ToString());
|
|
|
-
|
|
|
- statement.MoveNext();
|
|
|
+ statement.TryBindNull("@UserId");
|
|
|
}
|
|
|
- }, TransactionMode);
|
|
|
- }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ statement.TryBind("@UserId", entry.UserId.ToString("N"));
|
|
|
+ }
|
|
|
+
|
|
|
+ statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue());
|
|
|
+ statement.TryBind("@LogSeverity", entry.Severity.ToString());
|
|
|
+
|
|
|
+ statement.MoveNext();
|
|
|
+ }
|
|
|
+ }, TransactionMode);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -128,132 +126,128 @@ namespace Emby.Server.Implementations.Activity
|
|
|
}
|
|
|
|
|
|
using (WriteLock.Write())
|
|
|
+ using (var connection = CreateConnection())
|
|
|
{
|
|
|
- using (var connection = CreateConnection())
|
|
|
+ connection.RunInTransaction(db =>
|
|
|
{
|
|
|
- connection.RunInTransaction(db =>
|
|
|
+ using (var statement = db.PrepareStatement("Update ActivityLog set Name=@Name,Overview=@Overview,ShortOverview=@ShortOverview,Type=@Type,ItemId=@ItemId,UserId=@UserId,DateCreated=@DateCreated,LogSeverity=@LogSeverity where Id=@Id"))
|
|
|
{
|
|
|
- using (var statement = db.PrepareStatement("Update ActivityLog set Name=@Name,Overview=@Overview,ShortOverview=@ShortOverview,Type=@Type,ItemId=@ItemId,UserId=@UserId,DateCreated=@DateCreated,LogSeverity=@LogSeverity where Id=@Id"))
|
|
|
+ statement.TryBind("@Id", entry.Id);
|
|
|
+
|
|
|
+ statement.TryBind("@Name", entry.Name);
|
|
|
+ statement.TryBind("@Overview", entry.Overview);
|
|
|
+ statement.TryBind("@ShortOverview", entry.ShortOverview);
|
|
|
+ statement.TryBind("@Type", entry.Type);
|
|
|
+ statement.TryBind("@ItemId", entry.ItemId);
|
|
|
+
|
|
|
+ if (entry.UserId.Equals(Guid.Empty))
|
|
|
{
|
|
|
- statement.TryBind("@Id", entry.Id);
|
|
|
-
|
|
|
- statement.TryBind("@Name", entry.Name);
|
|
|
- statement.TryBind("@Overview", entry.Overview);
|
|
|
- statement.TryBind("@ShortOverview", entry.ShortOverview);
|
|
|
- statement.TryBind("@Type", entry.Type);
|
|
|
- statement.TryBind("@ItemId", entry.ItemId);
|
|
|
-
|
|
|
- if (entry.UserId.Equals(Guid.Empty))
|
|
|
- {
|
|
|
- statement.TryBindNull("@UserId");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- statement.TryBind("@UserId", entry.UserId.ToString("N"));
|
|
|
- }
|
|
|
-
|
|
|
- statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue());
|
|
|
- statement.TryBind("@LogSeverity", entry.Severity.ToString());
|
|
|
-
|
|
|
- statement.MoveNext();
|
|
|
+ statement.TryBindNull("@UserId");
|
|
|
}
|
|
|
- }, TransactionMode);
|
|
|
- }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ statement.TryBind("@UserId", entry.UserId.ToString("N"));
|
|
|
+ }
|
|
|
+
|
|
|
+ statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue());
|
|
|
+ statement.TryBind("@LogSeverity", entry.Severity.ToString());
|
|
|
+
|
|
|
+ statement.MoveNext();
|
|
|
+ }
|
|
|
+ }, TransactionMode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit)
|
|
|
{
|
|
|
using (WriteLock.Read())
|
|
|
+ using (var connection = CreateConnection(true))
|
|
|
{
|
|
|
- using (var connection = CreateConnection(true))
|
|
|
- {
|
|
|
- var commandText = BaseActivitySelectText;
|
|
|
- var whereClauses = new List<string>();
|
|
|
+ var commandText = BaseActivitySelectText;
|
|
|
+ var whereClauses = new List<string>();
|
|
|
|
|
|
- if (minDate.HasValue)
|
|
|
+ if (minDate.HasValue)
|
|
|
+ {
|
|
|
+ whereClauses.Add("DateCreated>=@DateCreated");
|
|
|
+ }
|
|
|
+ if (hasUserId.HasValue)
|
|
|
+ {
|
|
|
+ if (hasUserId.Value)
|
|
|
{
|
|
|
- whereClauses.Add("DateCreated>=@DateCreated");
|
|
|
+ whereClauses.Add("UserId not null");
|
|
|
}
|
|
|
- if (hasUserId.HasValue)
|
|
|
+ else
|
|
|
{
|
|
|
- if (hasUserId.Value)
|
|
|
- {
|
|
|
- whereClauses.Add("UserId not null");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- whereClauses.Add("UserId is null");
|
|
|
- }
|
|
|
+ whereClauses.Add("UserId is null");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
|
|
- string.Empty :
|
|
|
- " where " + string.Join(" AND ", whereClauses.ToArray());
|
|
|
-
|
|
|
- if (startIndex.HasValue && startIndex.Value > 0)
|
|
|
- {
|
|
|
- var pagingWhereText = whereClauses.Count == 0 ?
|
|
|
- string.Empty :
|
|
|
- " where " + string.Join(" AND ", whereClauses.ToArray());
|
|
|
+ var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
|
|
+ string.Empty :
|
|
|
+ " where " + string.Join(" AND ", whereClauses.ToArray(whereClauses.Count));
|
|
|
|
|
|
- whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM ActivityLog {0} ORDER BY DateCreated DESC LIMIT {1})",
|
|
|
- pagingWhereText,
|
|
|
- startIndex.Value.ToString(_usCulture)));
|
|
|
- }
|
|
|
-
|
|
|
- var whereText = whereClauses.Count == 0 ?
|
|
|
+ if (startIndex.HasValue && startIndex.Value > 0)
|
|
|
+ {
|
|
|
+ var pagingWhereText = whereClauses.Count == 0 ?
|
|
|
string.Empty :
|
|
|
" where " + string.Join(" AND ", whereClauses.ToArray());
|
|
|
|
|
|
- commandText += whereText;
|
|
|
+ whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM ActivityLog {0} ORDER BY DateCreated DESC LIMIT {1})",
|
|
|
+ pagingWhereText,
|
|
|
+ startIndex.Value.ToString(_usCulture)));
|
|
|
+ }
|
|
|
|
|
|
- commandText += " ORDER BY DateCreated DESC";
|
|
|
+ var whereText = whereClauses.Count == 0 ?
|
|
|
+ string.Empty :
|
|
|
+ " where " + string.Join(" AND ", whereClauses.ToArray(whereClauses.Count));
|
|
|
|
|
|
- if (limit.HasValue)
|
|
|
- {
|
|
|
- commandText += " LIMIT " + limit.Value.ToString(_usCulture);
|
|
|
- }
|
|
|
+ commandText += whereText;
|
|
|
|
|
|
- var statementTexts = new List<string>();
|
|
|
- statementTexts.Add(commandText);
|
|
|
- statementTexts.Add("select count (Id) from ActivityLog" + whereTextWithoutPaging);
|
|
|
+ commandText += " ORDER BY DateCreated DESC";
|
|
|
|
|
|
- return connection.RunInTransaction(db =>
|
|
|
- {
|
|
|
- var list = new List<ActivityLogEntry>();
|
|
|
- var result = new QueryResult<ActivityLogEntry>();
|
|
|
+ if (limit.HasValue)
|
|
|
+ {
|
|
|
+ commandText += " LIMIT " + limit.Value.ToString(_usCulture);
|
|
|
+ }
|
|
|
|
|
|
- var statements = PrepareAllSafe(db, statementTexts).ToList();
|
|
|
+ var statementTexts = new List<string>();
|
|
|
+ statementTexts.Add(commandText);
|
|
|
+ statementTexts.Add("select count (Id) from ActivityLog" + whereTextWithoutPaging);
|
|
|
+
|
|
|
+ return connection.RunInTransaction(db =>
|
|
|
+ {
|
|
|
+ var list = new List<ActivityLogEntry>();
|
|
|
+ var result = new QueryResult<ActivityLogEntry>();
|
|
|
|
|
|
- using (var statement = statements[0])
|
|
|
+ var statements = PrepareAllSafe(db, statementTexts).ToList();
|
|
|
+
|
|
|
+ using (var statement = statements[0])
|
|
|
+ {
|
|
|
+ if (minDate.HasValue)
|
|
|
{
|
|
|
- if (minDate.HasValue)
|
|
|
- {
|
|
|
- statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var row in statement.ExecuteQuery())
|
|
|
- {
|
|
|
- list.Add(GetEntry(row));
|
|
|
- }
|
|
|
+ statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
|
|
}
|
|
|
|
|
|
- using (var statement = statements[1])
|
|
|
+ foreach (var row in statement.ExecuteQuery())
|
|
|
{
|
|
|
- if (minDate.HasValue)
|
|
|
- {
|
|
|
- statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
|
|
- }
|
|
|
+ list.Add(GetEntry(row));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- result.TotalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
|
|
+ using (var statement = statements[1])
|
|
|
+ {
|
|
|
+ if (minDate.HasValue)
|
|
|
+ {
|
|
|
+ statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
|
|
}
|
|
|
|
|
|
- result.Items = list.ToArray();
|
|
|
- return result;
|
|
|
+ result.TotalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
|
|
+ }
|
|
|
|
|
|
- }, ReadTransactionMode);
|
|
|
- }
|
|
|
+ result.Items = list.ToArray(list.Count);
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }, ReadTransactionMode);
|
|
|
}
|
|
|
}
|
|
|
|