Use Arrays insted of Lists for better performance
This commit is contained in:
@@ -9,7 +9,7 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
|
|
||||||
DatabaseService _databaseService;
|
DatabaseService _databaseService;
|
||||||
|
|
||||||
public static List<Product> CatalogItems = new List<Product>();
|
public static Product[] CatalogItems = [];
|
||||||
|
|
||||||
public ProductController( DatabaseService databaseService ) {
|
public ProductController( DatabaseService databaseService ) {
|
||||||
_databaseService = databaseService;
|
_databaseService = databaseService;
|
||||||
@@ -114,8 +114,8 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
if( !string.IsNullOrEmpty( email ) ) {
|
if( !string.IsNullOrEmpty( email ) ) {
|
||||||
Account? test = await _databaseService.GetAccount(email);
|
Account? test = await _databaseService.GetAccount(email);
|
||||||
if( test != null ) {
|
if( test != null ) {
|
||||||
List<Receipt> returned = await _databaseService.GetAllReceipts(test);
|
Receipt[] returned = await _databaseService.GetAllReceipts(test);
|
||||||
return returned.ToArray();
|
return returned;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
if( !string.IsNullOrEmpty( email ) ) {
|
if( !string.IsNullOrEmpty( email ) ) {
|
||||||
Account? user = await _databaseService.GetAccount(email);
|
Account? user = await _databaseService.GetAccount(email);
|
||||||
if (user != null){
|
if (user != null){
|
||||||
List<Product>? games = await _databaseService.GetAllProducts();
|
Product[] games = await _databaseService.GetAllProducts();
|
||||||
foreach( Product product in games ) {
|
foreach( Product product in games ) {
|
||||||
if ( contains( Product, product.URL ) ) {
|
if ( contains( Product, product.URL ) ) {
|
||||||
Receipt? receipt = await _databaseService.GetReceipt(user, product);
|
Receipt? receipt = await _databaseService.GetReceipt(user, product);
|
||||||
@@ -175,13 +175,14 @@ namespace MistoxWebsite.Server.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async Task HotReload( DatabaseService ds ) {
|
public static async Task HotReload( DatabaseService ds ) {
|
||||||
CatalogItems = new List<Product>();
|
|
||||||
try {
|
try {
|
||||||
CatalogItems = await ds.GetAllProducts();
|
CatalogItems = await ds.GetAllProducts();
|
||||||
} catch {
|
} catch {
|
||||||
CatalogItems.Add( new Product() { ID = 0, Name = "offline prod1", Cost = 100, Description = "offline desc" } );
|
CatalogItems = new Product[]{
|
||||||
CatalogItems.Add( new Product() { ID = 1, Name = "offline prod2", Cost = 100, Description = "offline desc" } );
|
new Product() { ID = 0, Name = "offline prod1", Cost = 100, Description = "offline desc" },
|
||||||
CatalogItems.Add( new Product() { ID = 2, Name = "offline prod3", 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 {
|
namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||||
public partial class 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>();
|
List<UserInventory> list = new List<UserInventory>();
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
@@ -40,7 +40,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task UpdateInventory( MySqlConnection connection, AccountInventory item ) {
|
async Task UpdateInventory( MySqlConnection connection, AccountInventory item ) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Data.Common;
|
|||||||
namespace MistoxWebsite.Server.Services.DatabaseService {
|
namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||||
public partial class 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> ();
|
List<Receipt> receipts = new List<Receipt> ();
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
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();
|
List<( Receipt, Product )> join = new();
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
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 ) {
|
public async Task<Receipt?> GetReceipt( Account account, Product game ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user