Skip to content

Commit

Permalink
Hopefully increase performance + remove search limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed Mar 22, 2024
1 parent e6554f6 commit de2b367
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
24 changes: 23 additions & 1 deletion Client/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,26 @@
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
</div>

<script>
// This is very cursed, but it works
// I move all modals to the modal-root div
// also every time a modal is created, it is appended to the modal-root div
const modalRoot = document.getElementById('modal-root');
const pageRoot = document.querySelector('.page');
const modals = document.querySelectorAll('.modal');
modals.forEach(modal => {
modalRoot.appendChild(modal);
});
// listen for when a div is created with the class modal and move it to the modal-root div
const observer = new MutationObserver(function(mutations) {
const modals = document.querySelectorAll('.modal');
modals.forEach(modal => {
modalRoot.appendChild(modal);
});
});
observer.observe(pageRoot, { childList: true, subtree: true });
</script>
12 changes: 0 additions & 12 deletions Client/Components/ReplayViewer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,6 @@
<p>Oops! This component is missing a replay. Please report this to the developers.</p>
}

<script>
// This is very cursed, but it works
// I move the modal to the root of the document so it can be opened from anywhere
// this is because ReplayViewer may be rendered in a modal itself
// and modals can't be nested
var modals = document.querySelectorAll('.modal');
var modalRoot = document.getElementById('modal-root');
modals.forEach((modal) => {
modalRoot.appendChild(modal);
});
</script>

@code {
[Parameter]
public Shared.Models.Replay? Replay { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Server/Api/ReplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ [FromQuery] string query

var found = ReplayParser.SearchReplays(searchMode, query, _context);
// Order found replays by date
found = found.OrderByDescending(r => r.Date ?? DateTime.MinValue).Take(32 * 3).ToList();
found = found.OrderByDescending(r => r.Date ?? DateTime.MinValue).Take(Constants.SearchLimit).ToList();

return Ok(found);
}
Expand Down
6 changes: 6 additions & 0 deletions Shared/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Shared;

public class Constants
{
public const int SearchLimit = int.MaxValue;
}

0 comments on commit de2b367

Please sign in to comment.