mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 08:45:58 +03:00
[PR #5995] perf(backend): add indexes and optimize database queries #5451
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5451
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5995
Author: @tembo[bot]
Created: 3/16/2026
Status: 🔄 Open
Base:
next← Head:tembo/optimize-performance-db-queries📝 Commits (10+)
feb23dfperf(db): add indexes and optimize collection/request tree queries for better performancee3a46a3refactor(team-collection,user-collection): optimize export by bulk-fetching and in-memory tree building; fix prisma error handling in team service3a02f57chore(deps): update @types/node to 25.2.3 in pnpm-lock.yamlce6c7abperf(db): remove unused indexes and add updatedOn to request reordering queries0b23ed4fix(backend): address review comments and refine db query optimizationsdf0e81eperf(backend): add functional email index and fix raw SQL usage in orderIndex updates75d64eerefactor(user-collection): improve buildUserCollectionTree calls and add comments35ed66aperf(backend): add comments and fix null assertion for better code clarity28a31e3perf(db): add indexes and optimize batch update queries with safer SQL cases004021brefactor(admin,user-collection): improve type safety by explicit mappings📊 Changes
18 files changed (+463 additions, -457 deletions)
View changed files
➕
packages/hoppscotch-backend/prisma/migrations/20260316060000_add_performance_indexes/migration.sql(+48 -0)📝
packages/hoppscotch-backend/prisma/schema.prisma(+20 -0)📝
packages/hoppscotch-backend/src/admin/admin.service.spec.ts(+5 -27)📝
packages/hoppscotch-backend/src/admin/admin.service.ts(+28 -27)📝
packages/hoppscotch-backend/src/mock-server/mock-server.service.ts(+34 -24)📝
packages/hoppscotch-backend/src/shortcode/shortcode.service.spec.ts(+6 -6)📝
packages/hoppscotch-backend/src/shortcode/shortcode.service.ts(+1 -1)📝
packages/hoppscotch-backend/src/team-collection/team-collection.service.ts(+64 -59)📝
packages/hoppscotch-backend/src/team-request/team-request.service.spec.ts(+13 -10)📝
packages/hoppscotch-backend/src/team-request/team-request.service.ts(+14 -8)📝
packages/hoppscotch-backend/src/team/team.service.spec.ts(+14 -21)📝
packages/hoppscotch-backend/src/team/team.service.ts(+58 -95)📝
packages/hoppscotch-backend/src/user-collection/user-collection.service.ts(+108 -94)📝
packages/hoppscotch-backend/src/user-history/user-history.service.spec.ts(+3 -3)📝
packages/hoppscotch-backend/src/user-history/user-history.service.ts(+2 -4)📝
packages/hoppscotch-backend/src/user-request/user-request.service.ts(+12 -7)📝
packages/hoppscotch-backend/src/user/user.service.ts(+18 -17)📝
pnpm-lock.yaml(+15 -54)📄 Description
Summary
Optimizes database performance across the Hoppscotch backend by adding missing indexes, eliminating N+1 query patterns, and reducing round-trips for batch operations.
Changes
Database Indexes (12 new indexes)
TeamMember(userUid)— listing teams for a userTeamRequest(collectionID)— listing requests in a collectionTeamEnvironment(teamID)— listing environments in a teamUserHistory(userUid, reqType, executedOn DESC)— paginated history with orderingUserEnvironment(userUid)— listing user environmentsUserRequest(collectionID)— listing requests in a collectionPersonalAccessToken(userUid)— listing user tokensShortcode(creatorUid)— listing user's shortcodesMockServer(workspaceType, workspaceID, deletedAt)— filtered mock server listingMockServer(creatorUid, deletedAt)— user's mock serversAccount(userId)— user's provider accountsVerificationToken(userUid)— user's verification tokensQuery Optimizations
INclause withNOT EXISTSsubquery forfetchInvitedUsersUPDATEqueries with singleCASE WHENstatement; preserveupdatedOntimestampsdeleteManybeforeteam.delete(cascade handles it); batch user lookups viafindUsersByIds; singlegroupByfor sole-owner check; simplified cursor-based pagination.filter()calls for workspace statsfindFirst→findUniquefor primary key lookupsmode: 'insensitive'for case-insensitive searchTest Updates
Test plan
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.