mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-08 12:28:19 +02:00
Remove some unnecessary string allocations.
This commit is contained in:
parent
b7421db5fe
commit
aa32aba0f8
1 changed files with 20 additions and 113 deletions
|
@ -401,6 +401,8 @@ namespace Emby.Server.Implementations.Data
|
||||||
"OwnerId"
|
"OwnerId"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly string _retriveItemColumnsSelectQuery = $"select {string.Join(',', _retriveItemColumns)} from TypedBaseItems where guid = @guid";
|
||||||
|
|
||||||
private static readonly string[] _mediaStreamSaveColumns =
|
private static readonly string[] _mediaStreamSaveColumns =
|
||||||
{
|
{
|
||||||
"ItemId",
|
"ItemId",
|
||||||
|
@ -440,6 +442,12 @@ namespace Emby.Server.Implementations.Data
|
||||||
"ColorTransfer"
|
"ColorTransfer"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly string _mediaStreamSaveColumnsInsertQuery =
|
||||||
|
$"insert into mediastreams ({string.Join(',', _mediaStreamSaveColumns)}) values ";
|
||||||
|
|
||||||
|
private static readonly string _mediaStreamSaveColumnsSelectQuery =
|
||||||
|
$"select {string.Join(',', _mediaStreamSaveColumns)} from mediastreams where ItemId=@ItemId";
|
||||||
|
|
||||||
private static readonly string[] _mediaAttachmentSaveColumns =
|
private static readonly string[] _mediaAttachmentSaveColumns =
|
||||||
{
|
{
|
||||||
"ItemId",
|
"ItemId",
|
||||||
|
@ -451,102 +459,15 @@ namespace Emby.Server.Implementations.Data
|
||||||
"MIMEType"
|
"MIMEType"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly string _mediaAttachmentSaveColumnsSelectQuery =
|
||||||
|
$"select {string.Join(',', _mediaAttachmentSaveColumns)} from mediaattachments where ItemId=@ItemId";
|
||||||
|
|
||||||
private static readonly string _mediaAttachmentInsertPrefix;
|
private static readonly string _mediaAttachmentInsertPrefix;
|
||||||
|
|
||||||
private static string GetSaveItemCommandText()
|
private const string GetSaveItemCommandText =
|
||||||
{
|
@"replace into TypedBaseItems
|
||||||
var saveColumns = new[]
|
(guid,type,data,Path,StartDate,EndDate,ChannelId,IsMovie,IsSeries,EpisodeTitle,IsRepeat,CommunityRating,CustomRating,IndexNumber,IsLocked,Name,OfficialRating,MediaType,Overview,ParentIndexNumber,PremiereDate,ProductionYear,ParentId,Genres,InheritedParentalRatingValue,SortName,ForcedSortName,RunTimeTicks,Size,DateCreated,DateModified,PreferredMetadataLanguage,PreferredMetadataCountryCode,Width,Height,DateLastRefreshed,DateLastSaved,IsInMixedFolder,LockedFields,Studios,Audio,ExternalServiceId,Tags,IsFolder,UnratedType,TopParentId,TrailerTypes,CriticRating,CleanName,PresentationUniqueKey,OriginalTitle,PrimaryVersionId,DateLastMediaAdded,Album,IsVirtualItem,SeriesName,UserDataKey,SeasonName,SeasonId,SeriesId,ExternalSeriesId,Tagline,ProviderIds,Images,ProductionLocations,ExtraIds,TotalBitrate,ExtraType,Artists,AlbumArtists,ExternalId,SeriesPresentationUniqueKey,ShowId,OwnerId)
|
||||||
{
|
values (@guid,@type,@data,@Path,@StartDate,@EndDate,@ChannelId,@IsMovie,@IsSeries,@EpisodeTitle,@IsRepeat,@CommunityRating,@CustomRating,@IndexNumber,@IsLocked,@Name,@OfficialRating,@MediaType,@Overview,@ParentIndexNumber,@PremiereDate,@ProductionYear,@ParentId,@Genres,@InheritedParentalRatingValue,@SortName,@ForcedSortName,@RunTimeTicks,@Size,@DateCreated,@DateModified,@PreferredMetadataLanguage,@PreferredMetadataCountryCode,@Width,@Height,@DateLastRefreshed,@DateLastSaved,@IsInMixedFolder,@LockedFields,@Studios,@Audio,@ExternalServiceId,@Tags,@IsFolder,@UnratedType,@TopParentId,@TrailerTypes,@CriticRating,@CleanName,@PresentationUniqueKey,@OriginalTitle,@PrimaryVersionId,@DateLastMediaAdded,@Album,@IsVirtualItem,@SeriesName,@UserDataKey,@SeasonName,@SeasonId,@SeriesId,@ExternalSeriesId,@Tagline,@ProviderIds,@Images,@ProductionLocations,@ExtraIds,@TotalBitrate,@ExtraType,@Artists,@AlbumArtists,@ExternalId,@SeriesPresentationUniqueKey,@ShowId,@OwnerId)";
|
||||||
"guid",
|
|
||||||
"type",
|
|
||||||
"data",
|
|
||||||
"Path",
|
|
||||||
"StartDate",
|
|
||||||
"EndDate",
|
|
||||||
"ChannelId",
|
|
||||||
"IsMovie",
|
|
||||||
"IsSeries",
|
|
||||||
"EpisodeTitle",
|
|
||||||
"IsRepeat",
|
|
||||||
"CommunityRating",
|
|
||||||
"CustomRating",
|
|
||||||
"IndexNumber",
|
|
||||||
"IsLocked",
|
|
||||||
"Name",
|
|
||||||
"OfficialRating",
|
|
||||||
"MediaType",
|
|
||||||
"Overview",
|
|
||||||
"ParentIndexNumber",
|
|
||||||
"PremiereDate",
|
|
||||||
"ProductionYear",
|
|
||||||
"ParentId",
|
|
||||||
"Genres",
|
|
||||||
"InheritedParentalRatingValue",
|
|
||||||
"SortName",
|
|
||||||
"ForcedSortName",
|
|
||||||
"RunTimeTicks",
|
|
||||||
"Size",
|
|
||||||
"DateCreated",
|
|
||||||
"DateModified",
|
|
||||||
"PreferredMetadataLanguage",
|
|
||||||
"PreferredMetadataCountryCode",
|
|
||||||
"Width",
|
|
||||||
"Height",
|
|
||||||
"DateLastRefreshed",
|
|
||||||
"DateLastSaved",
|
|
||||||
"IsInMixedFolder",
|
|
||||||
"LockedFields",
|
|
||||||
"Studios",
|
|
||||||
"Audio",
|
|
||||||
"ExternalServiceId",
|
|
||||||
"Tags",
|
|
||||||
"IsFolder",
|
|
||||||
"UnratedType",
|
|
||||||
"TopParentId",
|
|
||||||
"TrailerTypes",
|
|
||||||
"CriticRating",
|
|
||||||
"CleanName",
|
|
||||||
"PresentationUniqueKey",
|
|
||||||
"OriginalTitle",
|
|
||||||
"PrimaryVersionId",
|
|
||||||
"DateLastMediaAdded",
|
|
||||||
"Album",
|
|
||||||
"IsVirtualItem",
|
|
||||||
"SeriesName",
|
|
||||||
"UserDataKey",
|
|
||||||
"SeasonName",
|
|
||||||
"SeasonId",
|
|
||||||
"SeriesId",
|
|
||||||
"ExternalSeriesId",
|
|
||||||
"Tagline",
|
|
||||||
"ProviderIds",
|
|
||||||
"Images",
|
|
||||||
"ProductionLocations",
|
|
||||||
"ExtraIds",
|
|
||||||
"TotalBitrate",
|
|
||||||
"ExtraType",
|
|
||||||
"Artists",
|
|
||||||
"AlbumArtists",
|
|
||||||
"ExternalId",
|
|
||||||
"SeriesPresentationUniqueKey",
|
|
||||||
"ShowId",
|
|
||||||
"OwnerId"
|
|
||||||
};
|
|
||||||
|
|
||||||
var saveItemCommandCommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns) + ") values (";
|
|
||||||
|
|
||||||
for (var i = 0; i < saveColumns.Length; i++)
|
|
||||||
{
|
|
||||||
if (i != 0)
|
|
||||||
{
|
|
||||||
saveItemCommandCommandText += ",";
|
|
||||||
}
|
|
||||||
|
|
||||||
saveItemCommandCommandText += "@" + saveColumns[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return saveItemCommandCommandText + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Save a standard item in the repo.
|
/// Save a standard item in the repo.
|
||||||
|
@ -637,7 +558,7 @@ namespace Emby.Server.Implementations.Data
|
||||||
{
|
{
|
||||||
var statements = PrepareAll(db, new string[]
|
var statements = PrepareAll(db, new string[]
|
||||||
{
|
{
|
||||||
GetSaveItemCommandText(),
|
GetSaveItemCommandText,
|
||||||
"delete from AncestorIds where ItemId=@ItemId"
|
"delete from AncestorIds where ItemId=@ItemId"
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
|
@ -1227,7 +1148,7 @@ namespace Emby.Server.Implementations.Data
|
||||||
|
|
||||||
using (var connection = GetConnection(true))
|
using (var connection = GetConnection(true))
|
||||||
{
|
{
|
||||||
using (var statement = PrepareStatement(connection, "select " + string.Join(",", _retriveItemColumns) + " from TypedBaseItems where guid = @guid"))
|
using (var statement = PrepareStatement(connection, _retriveItemColumnsSelectQuery))
|
||||||
{
|
{
|
||||||
statement.TryBind("@guid", id);
|
statement.TryBind("@guid", id);
|
||||||
|
|
||||||
|
@ -5895,10 +5816,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
|
||||||
throw new ArgumentNullException(nameof(query));
|
throw new ArgumentNullException(nameof(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdText = "select "
|
var cmdText = _mediaStreamSaveColumnsSelectQuery;
|
||||||
+ string.Join(",", _mediaStreamSaveColumns)
|
|
||||||
+ " from mediastreams where"
|
|
||||||
+ " ItemId=@ItemId";
|
|
||||||
|
|
||||||
if (query.Type.HasValue)
|
if (query.Type.HasValue)
|
||||||
{
|
{
|
||||||
|
@ -5977,15 +5895,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
|
||||||
|
|
||||||
while (startIndex < streams.Count)
|
while (startIndex < streams.Count)
|
||||||
{
|
{
|
||||||
var insertText = new StringBuilder("insert into mediastreams (");
|
var insertText = new StringBuilder(_mediaStreamSaveColumnsInsertQuery);
|
||||||
foreach (var column in _mediaStreamSaveColumns)
|
|
||||||
{
|
|
||||||
insertText.Append(column).Append(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove last comma
|
|
||||||
insertText.Length--;
|
|
||||||
insertText.Append(") values ");
|
|
||||||
|
|
||||||
var endIndex = Math.Min(streams.Count, startIndex + Limit);
|
var endIndex = Math.Min(streams.Count, startIndex + Limit);
|
||||||
|
|
||||||
|
@ -6252,10 +6162,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
|
||||||
throw new ArgumentNullException(nameof(query));
|
throw new ArgumentNullException(nameof(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdText = "select "
|
var cmdText = _mediaAttachmentSaveColumnsSelectQuery;
|
||||||
+ string.Join(",", _mediaAttachmentSaveColumns)
|
|
||||||
+ " from mediaattachments where"
|
|
||||||
+ " ItemId=@ItemId";
|
|
||||||
|
|
||||||
if (query.Index.HasValue)
|
if (query.Index.HasValue)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue