#202 : Optimisation du Dashboard.

This commit is contained in:
Loic Masi
2026-04-06 22:02:57 +02:00
parent 3859ba80a4
commit 20ef50cb51
9 changed files with 216 additions and 28 deletions

View File

@@ -208,6 +208,22 @@ namespace Webzine.Repository
}
}
/// <inheritdoc/>
public int CountWithBiography()
{
try
{
int count = this.context.Artistes.Count(a => !string.IsNullOrEmpty(a.Biographie));
this.logger.LogDebug("Nombre d'artistes avec biographie: {Count}", count);
return count;
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors du comptage des artistes avec biographie.");
throw;
}
}
/// <inheritdoc/>
public IEnumerable<Artiste> FindArtistes(int offset, int limit)
{

View File

@@ -325,4 +325,100 @@ public class DbTitreRepository : ITitreRepository
throw;
}
}
/// <inheritdoc/>
public int CountLike()
{
try
{
var likes = this.context.Titres.Sum(t => t.NbLikes);
return likes;
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors de la récupération des likes.");
throw;
}
}
/// <inheritdoc/>
public int CountLecture()
{
try
{
var lectures = this.context.Titres.Sum(t => t.NbLectures);
return lectures;
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors de la récupération des lectures.");
throw;
}
}
/// <inheritdoc/>
public string? FindMostReviewedArtistName()
{
try
{
return this.context.Titres
.AsNoTracking()
.GroupBy(t => new { t.IdArtiste, t.Artiste.Nom })
.OrderByDescending(g => g.Count())
.ThenBy(g => g.Key.Nom)
.Select(g => g.Key.Nom)
.FirstOrDefault();
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste le plus chroniqué.");
throw;
}
}
/// <inheritdoc/>
public string? FindArtistNameWithMostReviewedAlbums()
{
try
{
return this.context.Titres
.AsNoTracking()
.GroupBy(t => new { t.IdArtiste, t.Artiste.Nom })
.Select(g => new
{
g.Key.Nom,
AlbumCount = g.Select(t => t.Album).Distinct().Count(),
})
.OrderByDescending(x => x.AlbumCount)
.ThenBy(x => x.Nom)
.Select(x => x.Nom)
.FirstOrDefault();
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le plus d'albums chroniqués.");
throw;
}
}
/// <inheritdoc/>
public (int IdTitre, string Libelle)? FindMostPlayedTitle()
{
try
{
var result = this.context.Titres
.AsNoTracking()
.OrderByDescending(t => t.NbLectures)
.ThenBy(t => t.Libelle)
.Select(t => new { t.IdTitre, t.Libelle })
.FirstOrDefault();
return result == null ? null : (result.IdTitre, result.Libelle);
}
catch (Exception ex)
{
this.logger.LogError(ex, "Erreur lors de la recherche du titre le plus joué.");
throw;
}
}
}

View File

@@ -107,6 +107,12 @@ namespace Webzine.Repository
return this.dataStore.Artistes.Count(predicate);
}
/// <inheritdoc/>
public int CountWithBiography()
{
return this.dataStore.Artistes.Count(a => !string.IsNullOrEmpty(a.Biographie));
}
/// <inheritdoc/>
public IEnumerable<Artiste> FindArtistes(int offset, int limit)
{

View File

@@ -131,4 +131,54 @@ public class LocalTitreRepository : ITitreRepository
existingTitre.IdArtiste = titre.IdArtiste;
existingTitre.Styles = titre.Styles;
}
/// <inheritdoc/>
public int CountLike()
{
return this.dataStore.Titres.Sum(t => t.NbLikes);
}
/// <inheritdoc/>
public int CountLecture()
{
return this.dataStore.Titres.Sum(t => t.NbLectures);
}
/// <inheritdoc/>
public string? FindMostReviewedArtistName()
{
return this.dataStore.Titres
.GroupBy(t => t.Artiste)
.OrderByDescending(g => g.Count())
.ThenBy(g => g.Key?.Nom)
.Select(g => g.Key?.Nom)
.FirstOrDefault();
}
/// <inheritdoc/>
public string? FindArtistNameWithMostReviewedAlbums()
{
return this.dataStore.Titres
.GroupBy(t => t.Artiste)
.Select(g => new
{
ArtistName = g.Key?.Nom,
AlbumCount = g.Select(t => t.Album).Distinct().Count(),
})
.OrderByDescending(x => x.AlbumCount)
.ThenBy(x => x.ArtistName)
.Select(x => x.ArtistName)
.FirstOrDefault();
}
/// <inheritdoc/>
public (int IdTitre, string Libelle)? FindMostPlayedTitle()
{
Titre? titre = this.dataStore.Titres
.OrderByDescending(t => t.NbLectures)
.ThenBy(t => t.Libelle)
.FirstOrDefault();
return titre == null ? null : (titre.IdTitre, titre.Libelle);
}
}