Skip to content

fix: Improve performance for the TreeCommitHistory endpoint#1877

Open
alanpeixinho wants to merge 1 commit intokernelci:mainfrom
profusion:fix/improve-commit-history-performance
Open

fix: Improve performance for the TreeCommitHistory endpoint#1877
alanpeixinho wants to merge 1 commit intokernelci:mainfrom
profusion:fix/improve-commit-history-performance

Conversation

@alanpeixinho
Copy link
Copy Markdown
Contributor

@alanpeixinho alanpeixinho commented Apr 23, 2026

Summary

  • Optimize TreeCommitHistory endpoint with improved database queries for better performance
  • Add new TreeCommitsListView endpoint for future paginated tree commit listing
  • Update frontend CommitNavigationGraph component and API integration

How to Test

  1. Verify backend endpoints:
    • GET /api/tree/{tree_id}/commits-history/ - optimized commit history
    • GET /api/tree/{tree_id}/commits-list/ - commit listing
  2. Frontend:
    • Navigate to a tree details page
    • Verify CommitNavigationGraph renders correctly with commit history for builds, boots and tests.
    • Check that commit list view loads properly.
  3. Performance:
    • Compare response times for TreeCommitHistory endpoint before/after changes on large trees.

Closes #1883

@alanpeixinho alanpeixinho force-pushed the fix/improve-commit-history-performance branch 2 times, most recently from bdd01aa to 3c4f037 Compare April 24, 2026 14:58
@alanpeixinho alanpeixinho force-pushed the fix/improve-commit-history-performance branch from 3c4f037 to a1886f0 Compare April 24, 2026 20:53
@MarceloRobert MarceloRobert added Backend Most or all of the changes for this issue will be in the backend code. Queries Issue that involves modifying some DB query labels Apr 27, 2026
@alanpeixinho alanpeixinho force-pushed the fix/improve-commit-history-performance branch 12 times, most recently from c513c76 to 8db039a Compare April 29, 2026 23:58
@alanpeixinho alanpeixinho marked this pull request as ready for review April 30, 2026 00:02
@alanpeixinho alanpeixinho force-pushed the fix/improve-commit-history-performance branch 3 times, most recently from ade6703 to 1da2177 Compare April 30, 2026 12:51
Copy link
Copy Markdown
Collaborator

@MarceloRobert MarceloRobert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some filters are not working [in treeDetails]:

  • test hardware - 0 results
  • boot origin - not applying
  • test inconclusive status - missing data
  • boot inconclusive status - missing data
  • build inconclusive status - 0 results / missing data
  • test issue (uncategorized) - 0 results
  • build issue (real) - 0 results
  • boot issue (any) - 0 results

I'm also getting error 400 on trees without tree_name or git_branch. Maybe we could just fallback to the old endpoint in those cases.

Also also, the hardwareDetails page requests the commitHistory when there's a single tree selected but it is returning error 400 for me

Comment on lines +903 to +904
git_branch: Optional[str],
tree_name: Optional[str],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree_name and git_branch can be null but there's no query condition in the query if they are None

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to not apply filtering when not specified, do we have cases, where we want to search specifically for null branchs and tree names?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not common but there are cases of trees without name/branch. Ex.: broonie tree, even though the current commitHistory is not right here either, it at least lets the user navigate through the commits

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am adding an option to search for exactly NULL tree names and branches.
What I dislike is that it makes this parameters no longer trully an optional filter, as null is now just another id

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how we have to work with this database, unfortunately. I think you added the filter to the get_tree_commit_history_hashes_aggregated query but not for the get_tree_commits query

Comment thread backend/kernelCI_app/queries/tree.py Outdated
Comment on lines +1029 to +1032
if include_boots and not include_tests:
boot_filter = "\nAND t.path LIKE 'boot%%'"
elif include_tests and not include_boots:
boot_filter = "\nAND t.path NOT LIKE 'boot%%'"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the boot filter should be = boot or like boot.%. This is because a test called "bootloader_something" is not considered a boot test, only those with the specific name "boot" or "subtests" of boot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both conditions should apply at all times, so it should be

if include_boots and not include_tests:
    boot_filter = "\nAND (t.path ='boot' OR t.path LIKE 'boot.%%')"
elif include_tests and not include_boots:
    boot_filter = "\nAND t.path NOT LIKE 'boot.%%' AND t.path != 'boot'"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right. My oversight.

Copy link
Copy Markdown
Contributor

@gustavobtflores gustavobtflores May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is still missing, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this change was still local. It should have been updated now.

Comment thread backend/kernelCI_app/typeModels/treeCommits.py Outdated
Comment thread backend/kernelCI_app/views/treeCommitsHistory.py Outdated
@alanpeixinho
Copy link
Copy Markdown
Contributor Author

Some filters are not working [in treeDetails]:

  • test hardware - 0 results
  • boot origin - not applying
  • test inconclusive status - missing data
  • boot inconclusive status - missing data
  • build inconclusive status - 0 results / missing data
  • test issue (uncategorized) - 0 results
  • build issue (real) - 0 results
  • boot issue (any) - 0 results

I'm also getting error 400 on trees without tree_name or git_branch. Maybe we could just fallback to the old endpoint in those cases.

Also also, the hardwareDetails page requests the commitHistory when there's a single tree selected but it is returning error 400 for me

The 400 returns was a choice for empty cases. Is it preferrable to return 200 and an empty list?

@MarceloRobert
Copy link
Copy Markdown
Collaborator

The 400 returns was a choice for empty cases. Is it preferrable to return 200 and an empty list?

For the cases that I have seen the error 400, they should actually be returning data, not be empty. As for when they should be empty, then I guess we have been using status 200 with an error message, but it can be up for debate again; my preference would be the 200 with "error" message (I know it's not a real error but the field in the response is called error)

@alanpeixinho alanpeixinho force-pushed the fix/improve-commit-history-performance branch 5 times, most recently from 6c5cd08 to 84b21c7 Compare May 5, 2026 23:26
@alanpeixinho alanpeixinho force-pushed the fix/improve-commit-history-performance branch from 84b21c7 to c2b8765 Compare May 6, 2026 02:06
    * Improve query performance for commit history
    * Add TreeCommitsListView and type models
    * Update frontend API and CommitNavigationGraph
@alanpeixinho alanpeixinho force-pushed the fix/improve-commit-history-performance branch from c2b8765 to f210cf7 Compare May 6, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend Most or all of the changes for this issue will be in the backend code. Queries Issue that involves modifying some DB query

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize TreeCommitHistory endpoint database queries for better performance

3 participants