mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Flatten using connection in GetMediaAttachments/SaveMediaAttachments
This commit is contained in:
parent
4573fb5301
commit
0dde5e46df
@ -6169,26 +6169,23 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
|
|||||||
|
|
||||||
cmdText += " order by AttachmentIndex ASC";
|
cmdText += " order by AttachmentIndex ASC";
|
||||||
|
|
||||||
using (var connection = GetConnection(true))
|
var list = new List<MediaAttachment>();
|
||||||
|
using var connection = GetConnection(true);
|
||||||
|
using (var statement = PrepareStatement(connection, cmdText))
|
||||||
{
|
{
|
||||||
var list = new List<MediaAttachment>();
|
statement.TryBind("@ItemId", query.ItemId.ToByteArray());
|
||||||
|
|
||||||
using (var statement = PrepareStatement(connection, cmdText))
|
if (query.Index.HasValue)
|
||||||
{
|
{
|
||||||
statement.TryBind("@ItemId", query.ItemId.ToByteArray());
|
statement.TryBind("@AttachmentIndex", query.Index.Value);
|
||||||
|
|
||||||
if (query.Index.HasValue)
|
|
||||||
{
|
|
||||||
statement.TryBind("@AttachmentIndex", query.Index.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var row in statement.ExecuteQuery()) {
|
|
||||||
list.Add(GetMediaAttachment(row));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
foreach (var row in statement.ExecuteQuery()) {
|
||||||
|
list.Add(GetMediaAttachment(row));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveMediaAttachments(Guid id, List<MediaAttachment> attachments, CancellationToken cancellationToken)
|
public void SaveMediaAttachments(Guid id, List<MediaAttachment> attachments, CancellationToken cancellationToken)
|
||||||
@ -6204,18 +6201,16 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
|
|||||||
throw new ArgumentNullException(nameof(attachments));
|
throw new ArgumentNullException(nameof(attachments));
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var connection = GetConnection())
|
using var connection = GetConnection();
|
||||||
|
connection.RunInTransaction(db =>
|
||||||
{
|
{
|
||||||
connection.RunInTransaction(db =>
|
var itemIdBlob = id.ToByteArray();
|
||||||
{
|
|
||||||
var itemIdBlob = id.ToByteArray();
|
|
||||||
|
|
||||||
db.Execute("delete from mediaattachments where ItemId=@ItemId", itemIdBlob);
|
db.Execute("delete from mediaattachments where ItemId=@ItemId", itemIdBlob);
|
||||||
|
|
||||||
InsertMediaAttachments(itemIdBlob, attachments, db);
|
InsertMediaAttachments(itemIdBlob, attachments, db);
|
||||||
|
|
||||||
}, TransactionMode);
|
}, TransactionMode);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InsertMediaAttachments(byte[] idBlob, List<MediaAttachment> attachments, IDatabaseConnection db)
|
private void InsertMediaAttachments(byte[] idBlob, List<MediaAttachment> attachments, IDatabaseConnection db)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user