Performance: Guard interface (canActivate)
MEDIUM IMPACT
This affects the request handling speed and responsiveness by controlling route access before controller execution.
async canActivate(context: ExecutionContext): Promise<boolean> { const user = await this.userService.findUserAsync(); return user?.isActive ?? false; }
canActivate(context: ExecutionContext): boolean {
// heavy synchronous logic like complex DB queries or CPU-intensive tasks
const user = this.userService.findUserSync();
return user && user.isActive;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous heavy logic in canActivate | N/A | N/A | N/A | [X] Bad |
| Asynchronous lightweight checks in canActivate | N/A | N/A | N/A | [OK] Good |