Skip to content

Add database indexes for perf improvements#1318

Merged
morganbr merged 4 commits into
PuzzleServer:mainfrom
roger-wolfson:main
May 27, 2026
Merged

Add database indexes for perf improvements#1318
morganbr merged 4 commits into
PuzzleServer:mainfrom
roger-wolfson:main

Conversation

@roger-wolfson
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread Data/PuzzleServerContext.cs Outdated
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ContentFile>().HasIndex(contentFile => new { contentFile.EventID, contentFile.ShortName }).IsUnique();
modelBuilder.Entity<ContentFile>().HasIndex(contentFile => new { contentFile.EventID, contentFile.FileType}).IncludeProperties(contentFile => new { contentFile.ShortName, contentFile.UrlString, contentFile.PuzzleID}).IsUnique();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be non-unique since we can have multiple puzzles/solutions in an event

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be lying if I said I truly knew how to read this line of code, but short names and URL strings are unique per event, correct?


b.HasIndex("PuzzleID");

b.HasIndex("EventID", "FileType")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to regenerate the 3 migration files after your fixes to the model

Comment thread Data/PuzzleServerContext.cs Outdated
modelBuilder.Entity<Room>().HasIndex(room => new { room.EventID, room.Building, room.Number }).IsUnique();
modelBuilder.Entity<PlayerInEvent>().HasIndex(pie => new { pie.PlayerId, pie.EventId});
modelBuilder.Entity<PuzzleUser>().HasIndex(pu => new { pu.IdentityUserId});
modelBuilder.Entity<TeamMembers>().HasIndex(tm => new { tm.ID }); //EF can't parse this for nested types, so this is a placeholder to manually edit the generated model to INDEX Team.ID, User.ID, INCLUDE Class.ID, ID, TemporaryClassID
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the existing clustered index should be on this column. Does this have an effect?

@morganbr morganbr merged commit a380e16 into PuzzleServer:main May 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants