/acc:check-lazy-loadingfrom acc
Analyzes PHP code for lazy loading issues: premature loading, missing pagination, over-eager loading, infinite scroll problems, and serialization triggers.
Ships in acc. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Analyze PHP code for lazy loading patterns and issues.
// PREMATURE: Loading before needed
public function getOrder(int $id): Order
{
$order = $this->repository->find($id);
$items = $order->getItems(); // Loads immediately
$customer = $order->getCustomer(); // Loads immediately
return $order; // Items and customer may not be used
}
// BETTER: Let caller decide
public function getOrder(int $id): Order
{
return $this->repository->find($id);
// Items load only when accessed
}
// NO PAGINATION: Loads entire table
public function listUsers(): array
{
return $this->userRepository->findAll();
}
// NO PAGINATION: API returns everything
public function getProducts(): JsonResponse
{
$products = $this->repository->findBy(['active' => true]);
return new JsonResponse($products); // Could be 100K products
}
// WITH PAGINATION:
public function listUsers(int $page = 1, int $limit = 20): array
{
return $this->repository->findBy(
[],
['createdAt' => 'DESC'],
$limit,
($page - 1) * $limit
);
}
// OVER-EAGER: Loading unused relations
$qb = $em->createQueryBuilder()
->select('u', 'o', 'p', 'c', 'a')
->from(User::class, 'u')
->join('u.orders', 'o')
->join('o.products', 'p')
->join('u.comments', 'c')
->join('u.addresses', 'a')
->where('u.id = :id');
// Only needed user name
// RIGHT-SIZED: Load what's needed
$qb = $em->createQueryBuilder()
->select('u.name')
->from(User::class, 'u')
->where('u.id = :id');
// SLOW: Offset-based pagination degrades
public function loadMore(int $offset): array
{
return $this->repository->findBy(
[],
['id' => 'DESC'],
20,
$offset // Slow when offset is large
);
}
// BETTER: Cursor-based pagination
public function loadMore(?int $lastId = null): array
{
$qb = $this->createQueryBuilder('p')
->orderBy('p.id', 'DESC')
->setMaxResults(20);
if ($lastId !== null) {
$qb->where('p.id < :lastId')
->setParameter('lastId', $lastId);
}
return $qb->getQuery()->getResult();
}
// PROBLEM: Lazy loading during JSON encode
public function getOrder(int $id): JsonResponse
{
$order = $this->repository->find($id);
return new JsonResponse($order);
// Serializer may trigger lazy loading of all relations
}
// FIXED: Explicit DTO or groups
public function getOrder(int $id): JsonResponse
{
$order = $this->repository->find($id);
return $this->json($order, 200, [], ['groups' => ['order:read']]);
}
// INEFFICIENT: Load all to count
$users = $this->repository->findBy(['status' => 'active']);
$count = count($users); // Loaded all users just to count
// EFFICIENT: COUNT query
$count = $this->repository->count(['status' => 'active']);
// EFFICIENT: DQL count
$count = $em->createQuery(
'SELECT COUNT(u) FROM User u WHERE u.status = :status'
)->setParameter('status', 'active')
->getSingleScalarResult();
// INEFFICIENT: Load entity to check existence
$user = $this->repository->find($id);
if ($user !== null) {
// User exists
}
// EFFICIENT: EXISTS query or count
$exists = $this->repository->count(['id' => $id]) > 0;
// EFFICIENT: DQL
$exists = (bool) $em->createQuery(
'SELECT 1 FROM User u WHERE u.id = :id'
)->setParameter('id', $id)
->setMaxResults(1)
->getOneOrNullResult();
// INEFFICIENT: Load full entity for one field
$user = $this->repository->find($id);
$email = $user->getEmail();
// EFFICIENT: Select only needed field
$email = $em->createQuery(
'SELECT u.email FROM User u WHERE u.id = :id'
)->setParameter('id', $id)
->getSingleScalarResult();
// EFFICIENT: Partial object
$user = $em->createQuery(
'SELECT partial u.{id, email} FROM User u WHERE u.id = :id'
)->setParameter('id', $id)
->getSingleResult();
# findAll usage
Grep: "->findAll\(\)" --glob "**/*.php"
# count(findBy)
Grep: "count\(.*->find" --glob "**/*.php"
# Large offset
Grep: "OFFSET\s+\$|setFirstResult\(" --glob "**/*.php"
# Missing limit
Grep: "findBy\([^)]+\)\s*;" --glob "**/*.php"
$results = $repository->findBy(
$criteria,
['id' => 'DESC'],
$limit,
$offset
);
$qb = $this->createQueryBuilder('e')
->where('e.id < :cursor')
->setParameter('cursor', $cursor)
->orderBy('e.id', 'DESC')
->setMaxResults($limit);
$qb = $this->createQueryBuilder('e')
->where('(e.createdAt, e.id) < (:createdAt, :id)')
->setParameters([
'createdAt' => $lastCreatedAt,
'id' => $lastId,
])
->orderBy('e.createdAt', 'DESC')
->addOrderBy('e.id', 'DESC')
->setMaxResults($limit);
| Pattern | Severity |
|---|---|
| Missing pagination on list endpoint | 🔴 Critical |
| Load all to count | 🟠 Major |
| Large offset pagination | 🟠 Major |
| Full entity for single field | 🟡 Minor |
| Over-eager loading | 🟡 Minor |
### Lazy Loading Issue: [Description]
**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Type:** [Missing Pagination|Premature Loading|...]
**Issue:**
[Description of the lazy loading problem]
**Code:**
```php
// Current code
Fix:
// Optimized code
Improvement: Data loaded: 10,000 records → 20 records per page Memory: 50 MB → 1 MB
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub dykyi-roman/awesome-claude-code --plugin acc283 skills in this plugin
/access-control-knowledgeAccess Control knowledge base. Provides ACL, RBAC, ABAC, ReBAC models, multi-tenancy patterns, and PHP implementations (Symfony Voters, Laravel Gates) for security audits and generation./adr-knowledgeAction-Domain-Responder pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for ADR (web-specific MVC alternative) audits./adr-templateGenerates Architecture Decision Records (ADR) for PHP projects. Creates structured decision documentation with context, decision, and consequences.Other plugins' skills for the same job