mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-23 02:27:17 +00:00
improve performance of getting channel list
This commit is contained in:
@@ -146,7 +146,7 @@ namespace Emby.Server.Implementations.Dto
|
||||
|
||||
if (channelTuples.Count > 0)
|
||||
{
|
||||
_livetvManager().AddChannelInfo(channelTuples, options, user);
|
||||
await _livetvManager().AddChannelInfo(channelTuples, options, user).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -161,7 +161,8 @@ namespace Emby.Server.Implementations.Dto
|
||||
if (tvChannel != null)
|
||||
{
|
||||
var list = new List<Tuple<BaseItemDto, LiveTvChannel>> { new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel) };
|
||||
_livetvManager().AddChannelInfo(list, options, user);
|
||||
var task = _livetvManager().AddChannelInfo(list, options, user);
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
else if (item is LiveTvProgram)
|
||||
{
|
||||
|
||||
@@ -2284,7 +2284,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
};
|
||||
}
|
||||
|
||||
public void AddChannelInfo(List<Tuple<BaseItemDto, LiveTvChannel>> tuples, DtoOptions options, User user)
|
||||
public async Task AddChannelInfo(List<Tuple<BaseItemDto, LiveTvChannel>> tuples, DtoOptions options, User user)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
@@ -2304,6 +2304,12 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
|
||||
RemoveFields(options);
|
||||
|
||||
var currentProgramsList = new List<BaseItem>();
|
||||
var currentChannelsDict = new Dictionary<string, BaseItemDto>();
|
||||
|
||||
var addCurrentProgram = options.AddCurrentProgram;
|
||||
var addMediaSources = options.Fields.Contains(ItemFields.MediaSources);
|
||||
|
||||
foreach (var tuple in tuples)
|
||||
{
|
||||
var dto = tuple.Item1;
|
||||
@@ -2314,19 +2320,38 @@ namespace Emby.Server.Implementations.LiveTv
|
||||
dto.ChannelType = channel.ChannelType;
|
||||
dto.ServiceName = channel.ServiceName;
|
||||
|
||||
if (options.Fields.Contains(ItemFields.MediaSources))
|
||||
currentChannelsDict[dto.Id] = dto;
|
||||
|
||||
if (addMediaSources)
|
||||
{
|
||||
dto.MediaSources = channel.GetMediaSources(true).ToList();
|
||||
}
|
||||
|
||||
if (options.AddCurrentProgram)
|
||||
if (addCurrentProgram)
|
||||
{
|
||||
var channelIdString = channel.Id.ToString("N");
|
||||
var currentProgram = programs.FirstOrDefault(i => string.Equals(i.ChannelId, channelIdString));
|
||||
|
||||
if (currentProgram != null)
|
||||
{
|
||||
dto.CurrentProgram = _dtoService.GetBaseItemDto(currentProgram, options, user);
|
||||
currentProgramsList.Add(currentProgram);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addCurrentProgram)
|
||||
{
|
||||
var currentProgramDtos = await _dtoService.GetBaseItemDtos(currentProgramsList, options, user).ConfigureAwait(false);
|
||||
|
||||
foreach (var programDto in currentProgramDtos)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(programDto.ChannelId))
|
||||
{
|
||||
BaseItemDto channelDto;
|
||||
if (currentChannelsDict.TryGetValue(programDto.ChannelId, out channelDto))
|
||||
{
|
||||
channelDto.CurrentProgram = programDto;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user