Use Arrays insted of Lists for better performance
This commit is contained in:
@@ -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" }
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Data.Common;
|
||||
namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||
public partial class DatabaseService {
|
||||
|
||||
public async Task<List<UserInventory>> GetInventory( Account account, Product product ) {
|
||||
public async Task<UserInventory[]> GetInventory( Account account, Product product ) {
|
||||
List<UserInventory> list = new List<UserInventory>();
|
||||
using( MySqlConnection connection = GetConnection() ) {
|
||||
connection.Open();
|
||||
@@ -40,7 +40,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
async Task UpdateInventory( MySqlConnection connection, AccountInventory item ) {
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Data.Common;
|
||||
namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||
public partial class DatabaseService {
|
||||
|
||||
public async Task<List<Receipt>> GetAllReceipts( Account account ) {
|
||||
public async Task<Receipt[]> GetAllReceipts( Account account ) {
|
||||
List<Receipt> receipts = new List<Receipt> ();
|
||||
using( MySqlConnection connection = GetConnection() ) {
|
||||
connection.Open();
|
||||
@@ -43,10 +43,10 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||
}
|
||||
}
|
||||
}
|
||||
return receipts;
|
||||
return receipts.ToArray();
|
||||
}
|
||||
|
||||
public async Task<List<( Receipt, Product )>> GetAllReceiptsJoinedToProduct( Account account ) {
|
||||
public async Task<( Receipt, Product )[]> GetAllReceiptsJoinedToProduct( Account account ) {
|
||||
List<( Receipt, Product )> join = new();
|
||||
using( MySqlConnection connection = GetConnection() ) {
|
||||
connection.Open();
|
||||
@@ -100,7 +100,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||
}
|
||||
}
|
||||
}
|
||||
return join;
|
||||
return join.ToArray();
|
||||
}
|
||||
|
||||
public async Task<Receipt?> GetReceipt( Account account, Product game ) {
|
||||
|
||||
Reference in New Issue
Block a user