Skip to content

Commit 08715f2

Browse files
committed
performance improvements
1 parent e6329ba commit 08715f2

13 files changed

Lines changed: 991 additions & 48 deletions

HomeSpeaker.Server2/Data/MusicContext.cs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,65 @@ public class MusicContext : DbContext
77
public MusicContext(DbContextOptions<MusicContext> options) : base(options)
88
{
99

10-
} public DbSet<Thumbnail> Thumbnails { get; set; }
10+
}
11+
12+
protected override void OnModelCreating(ModelBuilder modelBuilder)
13+
{
14+
base.OnModelCreating(modelBuilder);
15+
16+
// RadioStream indexes
17+
modelBuilder.Entity<RadioStream>()
18+
.HasIndex(s => s.PlayCount)
19+
.IsDescending();
20+
21+
modelBuilder.Entity<RadioStream>()
22+
.HasIndex(s => s.DisplayOrder);
23+
24+
modelBuilder.Entity<RadioStream>()
25+
.HasIndex(s => s.Name);
26+
27+
// Playlist indexes
28+
modelBuilder.Entity<Playlist>()
29+
.HasIndex(p => p.Name);
30+
31+
// PlaylistItem indexes
32+
modelBuilder.Entity<PlaylistItem>()
33+
.HasIndex(pi => pi.Order);
34+
35+
modelBuilder.Entity<PlaylistItem>()
36+
.HasIndex(pi => new { pi.PlaylistId, pi.SongPath });
37+
38+
// Impression indexes
39+
modelBuilder.Entity<Impression>()
40+
.HasIndex(i => i.Timestamp);
41+
42+
modelBuilder.Entity<Impression>()
43+
.HasIndex(i => i.SongPath);
44+
45+
modelBuilder.Entity<Impression>()
46+
.HasIndex(i => i.PlayedBy);
47+
48+
// Thumbnail indexes
49+
modelBuilder.Entity<Thumbnail>()
50+
.HasIndex(t => new { t.Artist, t.Album });
51+
52+
// AnchorDefinitionEntity indexes
53+
modelBuilder.Entity<AnchorDefinitionEntity>()
54+
.HasIndex(ad => new { ad.IsActive, ad.Name });
55+
56+
// UserAnchorEntity indexes
57+
modelBuilder.Entity<UserAnchorEntity>()
58+
.HasIndex(ua => new { ua.UserId, ua.AnchorDefinitionId })
59+
.IsUnique();
60+
61+
// DailyAnchorEntity indexes
62+
modelBuilder.Entity<DailyAnchorEntity>()
63+
.HasIndex(da => new { da.UserId, da.Date });
64+
65+
modelBuilder.Entity<DailyAnchorEntity>()
66+
.HasIndex(da => new { da.Date, da.IsCompleted });
67+
}
68+
public DbSet<Thumbnail> Thumbnails { get; set; }
1169
public DbSet<Playlist> Playlists { get; set; }
1270
public DbSet<PlaylistItem> PlaylistItems { get; set; }
1371
public DbSet<Impression> Impressions { get; set; }

HomeSpeaker.Server2/Dockerfile

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
1+
# syntax=docker/dockerfile:1
12
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
23

3-
# This stage is used when running from VS in fast mode (Default for Debug configuration)
44
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
5-
RUN apt update && apt install --yes sox libsox-fmt-mp3 alsa-utils vlc ffmpeg
5+
6+
# Install runtime dependencies in one layer with cleanup
7+
# --no-install-recommends: Don't install recommended packages (saves 100-200MB)
8+
# apt-get clean + rm: Remove apt cache (saves 50-100MB)
9+
RUN apt-get update \
10+
&& apt-get install -y --no-install-recommends \
11+
sox \
12+
libsox-fmt-mp3 \
13+
alsa-utils \
14+
vlc \
15+
ffmpeg \
16+
curl \
17+
iputils-ping \
18+
&& apt-get clean \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
22+
CMD curl -f http://localhost:8080/health || exit 1
23+
624
WORKDIR /app
725
EXPOSE 8080
826
EXPOSE 8081
927

10-
# This stage is used to build the service project
11-
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
28+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS publish
1229
ARG BUILD_CONFIGURATION=Release
1330
WORKDIR /src
31+
1432
COPY ["HomeSpeaker.Server2/HomeSpeaker.Server2.csproj", "HomeSpeaker.Server2/"]
1533
COPY ["HomeSpeaker.Shared/HomeSpeaker.Shared.csproj", "HomeSpeaker.Shared/"]
1634
COPY ["HomeSpeaker.WebAssembly/HomeSpeaker.WebAssembly.csproj", "HomeSpeaker.WebAssembly/"]
17-
RUN dotnet restore "./HomeSpeaker.Server2/HomeSpeaker.Server2.csproj"
35+
36+
RUN --mount=type=cache,target=/root/.nuget/packages \
37+
dotnet restore "./HomeSpeaker.Server2/HomeSpeaker.Server2.csproj"
38+
1839
COPY . .
1940
WORKDIR "/src/HomeSpeaker.Server2"
20-
RUN dotnet build "./HomeSpeaker.Server2.csproj" -c $BUILD_CONFIGURATION -o /app/build
2141

22-
# This stage is used to publish the service project to be copied to the final stage
23-
FROM build AS publish
24-
ARG BUILD_CONFIGURATION=Release
25-
RUN dotnet publish "./HomeSpeaker.Server2.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
42+
RUN --mount=type=cache,target=/root/.nuget/packages \
43+
dotnet publish "./HomeSpeaker.Server2.csproj" \
44+
-c $BUILD_CONFIGURATION \
45+
-o /app/publish \
46+
/p:UseAppHost=false \
47+
--no-restore
2648

27-
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
2849
FROM base AS final
29-
RUN apt-get install -y curl iputils-ping
30-
RUN grep 1000 /etc/passwd
3150

32-
# RUN groupadd -g 1000 mygroup
33-
# RUN useradd -u 1000 -g mygroup -s /bin/bash -m homespeakeruser
34-
# RUN usermod -aG audio homespeakeruser
35-
RUN usermod -aG audio ubuntu
51+
RUN grep 1000 /etc/passwd && usermod -aG audio ubuntu
3652
USER ubuntu
3753

3854
WORKDIR /app

HomeSpeaker.Server2/HomeSpeaker.Server2.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3131
</PackageReference>
3232
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0" />
33+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.0" />
3334
<PackageReference Include="Microsoft.Fast.Components.FluentUI" Version="3.8.0" />
3435
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.2" />
3536
<PackageReference Include="OpenTelemetry.Api" Version="1.12.0" />

0 commit comments

Comments
 (0)