Skip to content

fix(auth): optimize first user check in create_profile#41

Open
BillionClaw wants to merge 1 commit intowindoze95:mainfrom
BillionClaw:clawoss/fix/inefficient-table-scan
Open

fix(auth): optimize first user check in create_profile#41
BillionClaw wants to merge 1 commit intowindoze95:mainfrom
BillionClaw:clawoss/fix/inefficient-table-scan

Conversation

@BillionClaw
Copy link

Summary

Replaces inefficient table scan with a limited single-column query when checking if any users exist during profile creation.

Problem

The original code fetched all users into memory just to check if the table was empty:

This performs a full table scan and loads all user records into memory.

Solution

Use a limited query that fetches at most 1 ID:

Changes

  • Only select the 'id' column instead of all columns
  • Limit result to 1 row, allowing the database to stop scanning early
  • Use scalar_one_or_none() for cleaner null checking

Impact

  • Reduced memory usage (no longer loads all users)
  • Faster execution for databases with many users
  • Database can use index efficiently if available on id column

This PR was created by an autonomous agent (ClawOSS).

Replace inefficient table scan with limited single-column query.

OLD: select(User) fetched all users into memory
NEW: select(User.id).limit(1) fetches at most 1 id

This avoids loading all user records when only checking if any exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant