< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.Item.KeyframeRepository
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/Item/KeyframeRepository.cs
Line coverage
14%
Covered lines: 2
Uncovered lines: 12
Coverable lines: 14
Total lines: 64
Line coverage: 14.2%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Map(...)0%620%
Map(...)100%210%
GetKeyframeData(...)100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/Item/KeyframeRepository.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Threading;
 5using System.Threading.Tasks;
 6using Jellyfin.Database.Implementations;
 7using Jellyfin.Database.Implementations.Entities;
 8using MediaBrowser.Controller.Persistence;
 9using Microsoft.EntityFrameworkCore;
 10
 11namespace Jellyfin.Server.Implementations.Item;
 12
 13/// <summary>
 14/// Repository for obtaining Keyframe data.
 15/// </summary>
 16public class KeyframeRepository : IKeyframeRepository
 17{
 18    private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
 19
 20    /// <summary>
 21    /// Initializes a new instance of the <see cref="KeyframeRepository"/> class.
 22    /// </summary>
 23    /// <param name="dbProvider">The EFCore db factory.</param>
 24    public KeyframeRepository(IDbContextFactory<JellyfinDbContext> dbProvider)
 25    {
 2126        _dbProvider = dbProvider;
 2127    }
 28
 29    private static MediaEncoding.Keyframes.KeyframeData Map(KeyframeData entity)
 30    {
 031        return new MediaEncoding.Keyframes.KeyframeData(
 032            entity.TotalDuration,
 033            (entity.KeyframeTicks ?? []).ToList());
 34    }
 35
 36    private KeyframeData Map(MediaEncoding.Keyframes.KeyframeData dto, Guid itemId)
 37    {
 038        return new()
 039        {
 040            ItemId = itemId,
 041            TotalDuration = dto.TotalDuration,
 042            KeyframeTicks = dto.KeyframeTicks.ToList()
 043        };
 44    }
 45
 46    /// <inheritdoc />
 47    public IReadOnlyList<MediaEncoding.Keyframes.KeyframeData> GetKeyframeData(Guid itemId)
 48    {
 049        using var context = _dbProvider.CreateDbContext();
 50
 051        return context.KeyframeData.AsNoTracking().Where(e => e.ItemId.Equals(itemId)).Select(e => Map(e)).ToList();
 052    }
 53
 54    /// <inheritdoc />
 55    public async Task SaveKeyframeDataAsync(Guid itemId, MediaEncoding.Keyframes.KeyframeData data, CancellationToken ca
 56    {
 57        using var context = _dbProvider.CreateDbContext();
 58        using var transaction = await context.Database.BeginTransactionAsync(cancellationToken).ConfigureAwait(false);
 59        await context.KeyframeData.Where(e => e.ItemId.Equals(itemId)).ExecuteDeleteAsync(cancellationToken).ConfigureAw
 60        await context.KeyframeData.AddAsync(Map(data, itemId), cancellationToken).ConfigureAwait(false);
 61        await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
 62        await transaction.CommitAsync(cancellationToken).ConfigureAwait(false);
 63    }
 64}