chore: optimise creditsController
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (pull_request) Successful in 59s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (pull_request) Successful in 59s
				
			Doing both lookups in parallel saves around 1 ms in the happy case (20% of baseline time), and in case nonce does not match, the error is simply raised as per usual with the inventory request being lightweight enough to be negligible. Noteworthy that this reasoning doesn't really work for other controllers because in the error case, the inventory request would still be quite significant, even if the HTTP request itself would still finish quickly.
This commit is contained in:
		
							parent
							
								
									e267ca8f55
								
							
						
					
					
						commit
						8683d4e85d
					
				@ -4,9 +4,15 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			|||||||
import { getInventory } from "@/src/services/inventoryService";
 | 
					import { getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const creditsController: RequestHandler = async (req, res) => {
 | 
					export const creditsController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const inventory = (
 | 
				
			||||||
 | 
					        await Promise.all([
 | 
				
			||||||
    const inventory = await getInventory(accountId, "RegularCredits TradesRemaining PremiumCreditsFree PremiumCredits");
 | 
					            getAccountIdForRequest(req),
 | 
				
			||||||
 | 
					            getInventory(
 | 
				
			||||||
 | 
					                req.query.accountId as string,
 | 
				
			||||||
 | 
					                "RegularCredits TradesRemaining PremiumCreditsFree PremiumCredits"
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        ])
 | 
				
			||||||
 | 
					    )[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const response = {
 | 
					    const response = {
 | 
				
			||||||
        RegularCredits: inventory.RegularCredits,
 | 
					        RegularCredits: inventory.RegularCredits,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user