Use Arrays insted of Lists for better performance

This commit is contained in:
2025-06-28 09:41:25 -07:00
parent ddebcaf8af
commit 3999bbed78
3 changed files with 15 additions and 14 deletions
@@ -9,7 +9,7 @@ namespace MistoxWebsite.Server.Controllers {
DatabaseService _databaseService;
public static List<Product> CatalogItems = new List<Product>();
public static Product[] CatalogItems = [];
public ProductController( DatabaseService databaseService ) {
_databaseService = databaseService;
@@ -114,8 +114,8 @@ namespace MistoxWebsite.Server.Controllers {
if( !string.IsNullOrEmpty( email ) ) {
Account? test = await _databaseService.GetAccount(email);
if( test != null ) {
List<Receipt> returned = await _databaseService.GetAllReceipts(test);
return returned.ToArray();
Receipt[] returned = await _databaseService.GetAllReceipts(test);
return returned;
}
}
}
@@ -145,7 +145,7 @@ namespace MistoxWebsite.Server.Controllers {
if( !string.IsNullOrEmpty( email ) ) {
Account? user = await _databaseService.GetAccount(email);
if (user != null){
List<Product>? games = await _databaseService.GetAllProducts();
Product[] games = await _databaseService.GetAllProducts();
foreach( Product product in games ) {
if ( contains( Product, product.URL ) ) {
Receipt? receipt = await _databaseService.GetReceipt(user, product);
@@ -175,13 +175,14 @@ namespace MistoxWebsite.Server.Controllers {
}
public static async Task HotReload( DatabaseService ds ) {
CatalogItems = new List<Product>();
try {
CatalogItems = await ds.GetAllProducts();
} catch {
CatalogItems.Add( new Product() { ID = 0, Name = "offline prod1", Cost = 100, Description = "offline desc" } );
CatalogItems.Add( new Product() { ID = 1, Name = "offline prod2", Cost = 100, Description = "offline desc" } );
CatalogItems.Add( new Product() { ID = 2, Name = "offline prod3", Cost = 100, Description = "offline desc" } );
CatalogItems = new Product[]{
new Product() { ID = 0, Name = "offline prod1", Cost = 100, Description = "offline desc" },
new Product() { ID = 1, Name = "offline prod2", Cost = 100, Description = "offline desc" },
new Product() { ID = 2, Name = "offline prod3", Cost = 100, Description = "offline desc" }
};
};
}