Skip to content

Database optimization: add missing indexes, refactor redundant queries#122

Open
ZeePearl56 wants to merge 1 commit into
SudiptaPaul-31:mainfrom
ZeePearl56:fix/73-database-optimization
Open

Database optimization: add missing indexes, refactor redundant queries#122
ZeePearl56 wants to merge 1 commit into
SudiptaPaul-31:mainfrom
ZeePearl56:fix/73-database-optimization

Conversation

@ZeePearl56

@ZeePearl56 ZeePearl56 commented Jun 27, 2026

Copy link
Copy Markdown

Closes #73

Summary

Implements comprehensive database optimization for #73. Adds 11 missing indexes across 7 tables, removes redundant query patterns, and documents the full index strategy.

Indexes Added (11 total)

  • snippets: owner_created, deleted_owner (partial)
  • snippet_verifications: snippet_active, wallet_active (partial)
  • verification_attempt_logs: snippet_time
  • snippet_permissions: snippet_grantee_active, active_granted (partial)
  • permission_activity_log: snippet_created
  • marketplace_listings: status_created
  • marketplace_purchases: buyer_purchased, listing_buyer_status
  • marketplace_audit_logs: entity_type_created

Redundant Query Refactors

File Fix Savings
snippet.service.ts:updateSnippet Removed redundant findById -1 query
snippet.service.ts:deleteSnippet Removed redundant findById -1 query
snippet.service.ts:restoreSnippet Removed raw SQL, enhanced restore() -1 query
snippet.service.ts:permanentlyDeleteSnippet Removed raw SQL, used RETURNING * -1 query
snippet.repository.ts Added is_deleted guards to update/delete/restore Data integrity
[id]/route.ts:GET Inlined owner check to skip getSnippetOwner -1 query
[id]/route.ts:DELETE Fixed pre-existing dead code after early return Bug fix

New Files

  • scripts/migrations/001_add_performance_indexes.sql
  • scripts/run-optimization-migration.ts
  • docs/database-optimization.md

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

@ZeePearl56 is attempting to deploy a commit to the Sudipta 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@ZeePearl56 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Database Optimization & Query Refactoring

1 participant