AOSSIE-Org / AOSSIE-Org/Ell-ena

BUG: N+1 query pattern in getTickets/getTasks/getTicketDetails causes performance issues

Open
#149 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
54
Forks
110
PR merge metrics
No merged PRs in 30d

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

**Issue Overview**

Several data-fetching methods in SupabaseService perform multiple sequential database queries for related user data.

For example:

- getTickets
- getTasks
- getTicketDetails
- getTaskDetails

These methods:
1. Fetch a list of tickets/tasks/comments.
2. Then, for each item, make additional queries to fetch creator/assignee/user info.

This creates an N+1 query pattern.

**Steps to Reproduce**

1. Create a team with multiple members.
2. Add 20–50 tasks or tickets.
3. Call getTickets() or getTasks().
4. Observe in logs or network panel that dozens of extra queries are executed (one per item for user info).

**Expected Behavior**

Related user data (creator, assignee, comment user) should be fetched in a single query using joins or views, not separate queries per row.
The number of database calls should be:

- O(1) per screen load
not
- O(n) per item.

**Actual Behavior**

For each ticket/task/comment:

- _getUserInfo() is called.
- This results in additional round-trips to the database.
- Performance degrades rapidly as data grows.

This will not scale for real teams.

**Why this issue matters**

This is not just micro-optimisation.
It directly affects:

- load time
- mobile data usage
- battery
- server cost
On real data sizes, this becomes a serious bottleneck.

### Record

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.