mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-25 03:36:51 +00:00
Make PhotoSubjects use a one to many relationship (#687)
* Attempt to remodel PhotoSubject and Photo relationship
* Fix migration name
* Use exactName for migration lock
* Revert "Use exactName for migration lock"
This reverts commit 76cee6a3ff
.
* Set command timeout to 5 minutes for database migrations
* Delete unused PhotoSubjects in migration
* Clean up website queries and finalize subject refactor
* Add migration to remove PhotoSubjectCollection
* Add grace period for container startup and optimize startup
* Make config backup copy original file
* Allow docker entrypoint to fix data permissions
This commit is contained in:
parent
35ea2682b9
commit
017dcd6888
22 changed files with 240 additions and 210 deletions
|
@ -76,21 +76,21 @@
|
|||
</i>
|
||||
</p>
|
||||
|
||||
@if (Model.Subjects.Count > 0)
|
||||
@if (Model.PhotoSubjects.Count > 0)
|
||||
{
|
||||
<p>
|
||||
<b>Photo contains @Model.Subjects.Count @(Model.Subjects.Count == 1 ? "person" : "people"):</b>
|
||||
<b>Photo contains @Model.PhotoSubjects.Count @(Model.PhotoSubjects.Count == 1 ? "person" : "people"):</b>
|
||||
</p>
|
||||
}
|
||||
<div id="hover-subjects-@Model.PhotoId">
|
||||
@foreach (PhotoSubject subject in Model.Subjects)
|
||||
@foreach (PhotoSubject subject in Model.PhotoSubjects)
|
||||
{
|
||||
@await subject.User.ToLink(Html, ViewData, language, timeZone)
|
||||
}
|
||||
</div>
|
||||
|
||||
@{
|
||||
PhotoSubject[] subjects = Model.Subjects.ToArray();
|
||||
PhotoSubject[] subjects = Model.PhotoSubjects.ToArray();
|
||||
foreach (PhotoSubject subject in subjects) subject.Username = subject.User.Username;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using System.Text;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
||||
|
@ -27,22 +28,39 @@ public class PhotosPage : BaseLayout
|
|||
{
|
||||
if (string.IsNullOrWhiteSpace(name)) name = "";
|
||||
|
||||
this.SearchValue = name.Replace(" ", string.Empty);
|
||||
IQueryable<Photo> photos = this.Database.Photos.Include(p => p.Creator)
|
||||
.Include(p => p.PhotoSubjects)
|
||||
.ThenInclude(ps => ps.User);
|
||||
|
||||
this.PhotoCount = await this.Database.Photos.Include
|
||||
(p => p.Creator)
|
||||
.CountAsync(p => p.Creator!.Username.Contains(this.SearchValue) || p.PhotoSubjectCollection.Contains(this.SearchValue));
|
||||
if (name.Contains("by:") || name.Contains("with:"))
|
||||
{
|
||||
foreach (string part in name.Split(" ", StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (part.Contains("by:"))
|
||||
{
|
||||
photos = photos.Where(p => p.Creator != null && p.Creator.Username.Contains(part.Replace("by:", "")));
|
||||
}
|
||||
else if (part.Contains("with:"))
|
||||
{
|
||||
photos = photos.Where(p => p.PhotoSubjects.Any(ps => ps.User.Username.Contains(part.Replace("with:", ""))));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
photos = photos.Where(p => p.Creator != null && (p.PhotoSubjects.Any(ps => ps.User.Username.Contains(name)) || p.Creator.Username.Contains(name)));
|
||||
}
|
||||
|
||||
this.SearchValue = name.Trim();
|
||||
|
||||
this.PhotoCount = await photos.CountAsync();
|
||||
|
||||
this.PageNumber = pageNumber;
|
||||
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.PhotoCount / ServerStatics.PageSize));
|
||||
|
||||
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/photos/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
|
||||
|
||||
this.Photos = await this.Database.Photos.Include
|
||||
(p => p.Creator)
|
||||
.Include(p => p.Slot)
|
||||
.Where(p => p.Creator!.Username.Contains(this.SearchValue) || p.PhotoSubjectCollection.Contains(this.SearchValue))
|
||||
.OrderByDescending(p => p.Timestamp)
|
||||
this.Photos = await photos.OrderByDescending(p => p.Timestamp)
|
||||
.Skip(pageNumber * ServerStatics.PageSize)
|
||||
.Take(ServerStatics.PageSize)
|
||||
.ToListAsync();
|
||||
|
|
|
@ -99,6 +99,8 @@ public class SlotPage : BaseLayout
|
|||
}
|
||||
|
||||
this.Photos = await this.Database.Photos.Include(p => p.Creator)
|
||||
.Include(p => p.PhotoSubjects)
|
||||
.ThenInclude(ps => ps.User)
|
||||
.OrderByDescending(p => p.Timestamp)
|
||||
.Where(r => r.SlotId == id)
|
||||
.Take(10)
|
||||
|
|
|
@ -57,26 +57,22 @@ public class SlotsPage : BaseLayout
|
|||
|
||||
string trimmedSearch = finalSearch.ToString().Trim();
|
||||
|
||||
this.SlotCount = await this.Database.Slots.Include(p => p.Creator)
|
||||
IQueryable<Slot> slots = this.Database.Slots.Include(p => p.Creator)
|
||||
.Where(p => p.Type == SlotType.User && !p.Hidden)
|
||||
.Where(p => p.Name.Contains(trimmedSearch))
|
||||
.Where(p => p.Creator != null && (targetAuthor == null || string.Equals(p.Creator.Username.ToLower(), targetAuthor.ToLower())))
|
||||
.Where(p => p.Creator != null && (!p.SubLevel || p.Creator == this.User))
|
||||
.Where(p => targetGame == null || p.GameVersion == targetGame)
|
||||
.CountAsync();
|
||||
.Where(p => targetGame == null || p.GameVersion == targetGame);
|
||||
|
||||
this.SlotCount = await slots.CountAsync();
|
||||
|
||||
this.PageNumber = pageNumber;
|
||||
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.SlotCount / ServerStatics.PageSize));
|
||||
|
||||
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
|
||||
|
||||
this.Slots = await this.Database.Slots.Include(p => p.Creator)
|
||||
.Where(p => p.Type == SlotType.User && !p.Hidden)
|
||||
.Where(p => p.Name.Contains(trimmedSearch))
|
||||
.Where(p => p.Creator != null && (targetAuthor == null || string.Equals(p.Creator.Username.ToLower(), targetAuthor.ToLower())))
|
||||
.Where(p => p.Creator != null && (!p.SubLevel || p.Creator == this.User))
|
||||
this.Slots = await slots
|
||||
.Where(p => p.Creator!.LevelVisibility == PrivacyType.All) // TODO: change check for when user is logged in
|
||||
.Where(p => targetGame == null || p.GameVersion == targetGame)
|
||||
.OrderByDescending(p => p.FirstUploaded)
|
||||
.Skip(pageNumber * ServerStatics.PageSize)
|
||||
.Take(ServerStatics.PageSize)
|
||||
|
|
|
@ -60,6 +60,8 @@ public class UserPage : BaseLayout
|
|||
}
|
||||
|
||||
this.Photos = await this.Database.Photos.Include(p => p.Slot)
|
||||
.Include(p => p.PhotoSubjects)
|
||||
.ThenInclude(ps => ps.User)
|
||||
.OrderByDescending(p => p.Timestamp)
|
||||
.Where(p => p.CreatorId == userId)
|
||||
.Take(6)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue