Performance: Pagination (PageNumber, Cursor, Limit/Offset)
MEDIUM IMPACT
Pagination affects how much data is loaded and rendered at once, impacting page load speed and responsiveness.
def get_items(request): cursor = request.GET.get('cursor') limit = 100 if cursor: items = Item.objects.filter(id__gt=cursor).order_by('id')[:limit] else: items = Item.objects.all().order_by('id')[:limit] return render(request, 'items.html', {'items': items})
def get_items(request): page = int(request.GET.get('page', 1)) limit = 100 offset = (page - 1) * limit items = Item.objects.all()[offset:offset+limit] return render(request, 'items.html', {'items': items})
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Limit/Offset Pagination on large data | High (many nodes) | Multiple reflows per page | High paint cost | [X] Bad |
| Cursor Pagination with indexed queries | Low (limited nodes) | Single reflow per page | Low paint cost | [OK] Good |