Code Room
Vibe codingMediumvc-g495
Subject Ai code reviewLevel Mid–Senior~16 minCommon in Databases & SQL interviewsIndustries Software development

Question

An AI wrote this Django management command to deactivate users who haven't logged in for a year. It runs nightly. On a 2-million-user table it takes hours and hammers the primary DB. Identify the inefficiency and rewrite it.

python
def deactivate_stale_users():    cutoff = timezone.now() - timedelta(days=365)    stale = User.objects.filter(last_login__lt=cutoff, is_active=True)    for user in stale:        user.is_active = False        user.save()        AuditLog.objects.create(user=user, action="auto_deactivate")
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.