Skip to content

[WIP] feat(issues): add next checkout after last seen - #2054

Draft
felipebergamin wants to merge 2 commits into
kernelci:mainfrom
profusion:feat/1958/issue-details/next-checkout
Draft

[WIP] feat(issues): add next checkout after last seen#2054
felipebergamin wants to merge 2 commits into
kernelci:mainfrom
profusion:feat/1958/issue-details/next-checkout

Conversation

@felipebergamin

@felipebergamin felipebergamin commented Aug 14, 2026

Copy link
Copy Markdown
Member

Expose the earliest later checkout on the same tree in issue extras, using start_time since parent-commit hierarchy is unavailable (#1958).


Visual reference

Captura_de_tela_20260817_161731

Expose the earliest later checkout on the same tree in issue extras,
using start_time since parent-commit hierarchy is unavailable (kernelci#1958).
Add a Next Checkout section after last-seen incident data using the
extras payload (kernelci#1958).

@alanpeixinho alanpeixinho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looking great so far

"""

with connection.cursor() as cursor:
cursor.execute(query, params)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might be worth adding cache here


query = """
WITH last_seen AS (
SELECT DISTINCT ON (IC.issue_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we might be able to be faster using a subquery to get strictly the next checkout on subquery.
This suggestion was made on cursor, so we need to validate if it is correct.

  WITH last_seen AS (                                                                                                                                                                                                                                                                                                          
      SELECT DISTINCT ON (IC.issue_id)                                                                                                                                                                                                                                                                                         
          IC.issue_id,                                                                                                                                                                                                                                                                                                         
          C.id AS last_checkout_id,                                                                                                                                                                                                                                                                                            
          C.start_time AS last_start_time,                                                                                                                                                                                                                                                                                     
          C.origin,                                                                                                                                                                                                                                                                                                            
          C.tree_name,                                                                                                                                                                                                                                                                                                         
          C.git_repository_url,                                                                                                                                                                                                                                                                                                
          C.git_repository_branch                                                                                                                                                                                                                                                                                              
      FROM                                                                                                                                                                                                                                                                                                                     
          incidents IC                                                                                                                                                                                                                                                                                                         
      LEFT JOIN tests T ON IC.test_id = T.id                                                                                                                                                                                                                                                                                   
      LEFT JOIN builds B ON (                                                                                                                                                                                                                                                                                                  
          IC.build_id = B.id                                                                                                                                                                                                                                                                                                   
          OR T.build_id = B.id                                                                                                                                                                                                                                                                                                 
      )                                                                                                                                                                                                                                                                                                                        
      LEFT JOIN checkouts C ON B.checkout_id = C.id                                                                                                                                                                                                                                                                            
      WHERE                                                                                                                                                                                                                                                                                                                    
          IC.issue_id = ANY(ARRAY['issue-id-1', 'issue-id-2'])  -- %(issue_id_list)s                                                                                                                                                                                                                                           
      ORDER BY                                                                                                                                                                                                                                                                                                                 
          IC.issue_id,                                                                                                                                                                                                                                                                                                         
          IC.issue_version DESC,                                                                                                                                                                                                                                                                                               
          IC._timestamp DESC                                                                                                                                                                                                                                                                                                   
  )                                                                                                                                                                                                                                                                                                                            
  SELECT                                                                                                                                                                                                                                                                                                                       
      LS.issue_id,                                                                                                                                                                                                                                                                                                             
      C.id AS checkout_id,                                                                                                                                                                                                                                                                                                     
      C.start_time,                                                                                                                                                                                                                                                                                                            
      C.git_commit_hash,                                                                                                                                                                                                                                                                                                       
      C.git_commit_name,                                                                                                                                                                                                                                                                                                       
      C.git_repository_url,                                                                                                                                                                                                                                                                                                    
      C.git_repository_branch,                                                                                                                                                                                                                                                                                                 
      C.tree_name,                                                                                                                                                                                                                                                                                                             
      C.origin                                                                                                                                                                                                                                                                                                                 
  FROM                                                                                                                                                                                                                                                                                                                         
      last_seen LS                                                                                                                                                                                                                                                                                                             
      CROSS JOIN LATERAL (                                                                                                                                                                                                                                                                                                     
          SELECT                                                                                                                                                                                                                                                                                                               
              C.id,                                                                                                                                                                                                                                                                                                            
              C.start_time,                                                                                                                                                                                                                                                                                                    
              C.git_commit_hash,                                                                                                                                                                                                                                                                                               
              C.git_commit_name,                                                                                                                                                                                                                                                                                               
              C.git_repository_url,                                                                                                                                                                                                                                                                                            
              C.git_repository_branch,                                                                                                                                                                                                                                                                                         
              C.tree_name,                                                                                                                                                                                                                                                                                                     
              C.origin                                                                                                                                                                                                                                                                                                         
          FROM                                                                                                                                                                                                                                                                                                                 
              checkouts C                                                                                                                                                                                                                                                                                                      
          WHERE                                                                                                                                                                                                                                                                                                                
              C.origin = LS.origin                                                                                                                                                                                                                                                                                             
              AND C.tree_name IS NOT DISTINCT FROM LS.tree_name                                                                                                                                                                                                                                                                
              AND C.git_repository_url IS NOT DISTINCT FROM LS.git_repository_url                                                                                                                                                                                                                                              
              AND C.git_repository_branch IS NOT DISTINCT FROM LS.git_repository_branch                                                                                                                                                                                                                                        
              AND C.start_time > LS.last_start_time                                                                                                                                                                                                                                                                            
          ORDER BY                                                                                                                                                                                                                                                                                                             
              C.start_time ASC,                                                                                                                                                                                                                                                                                                
              C.id ASC                                                                                                                                                                                                                                                                                                         
          LIMIT 1                                                                                                                                                                                                                                                                                                              
      ) C                                                                                                                                                                                                            
  WHERE                                                                                                                                                                                                              
      LS.last_checkout_id IS NOT NULL                                                                                                                                                                                
      AND LS.last_start_time IS NOT NULL; 

In simple tests it was reasonably faster. But at the same time, the issues query is not a slow one. So fell free to ignore if it can make the endpoint more complex.

### Original
Planning:
  Buffers: shared hit=53 read=1
Planning Time: 1.421 ms
Execution Time: 1499.004 ms

### Subquery
Planning:
  Buffers: shared hit=54
Planning Time: 1.093 ms
Execution Time: 73.985 ms

});
}, [data?.extra, formatMessage, issueId]);

const nextCheckoutSection: ISection | undefined = useMemo(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unrelated to this task. But at some point I think we need to do a full layout improvement on this page.
This presented information is already quite sparse, and could find a better way to organize it.
Again, for this specific task, we should focus on just providing the information.

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.

2 participants