Skip to content

Updates filter for excluding thread statuses - #4054

Merged
mouse-reeve merged 2 commits into
mainfrom
blocked-query
Jul 20, 2026
Merged

mouse-reeve merged 2 commits into
mainfrom
blocked-query

Conversation

@mouse-reeve

Copy link
Copy Markdown
Member

Description

Changes the logic in searching for threads related to a blocked book

  • Related Issue #
  • Closes #

What type of Pull Request is this?

  • Bug Fix
  • Enhancement
  • Plumbing / Internals / Dependencies
  • Refactor

Does this PR change settings or dependencies, or break something?

  • This PR changes or adds default settings, configuration, or .env values
  • This PR changes or adds dependencies
  • This PR introduces other breaking changes

Details of breaking or configuration changes (if any of above checked)

Documentation

  • New or amended documentation will be required if this PR is merged
  • I have created a matching pull request in the Documentation repository
  • I intend to create a matching pull request in the Documentation repository after this PR is merged

Tests

  • My changes do not need new tests
  • All tests I have added are passing
  • I have written tests but need help to make them pass
  • I have not written tests and need help to write them

@mouse-reeve

Copy link
Copy Markdown
Member Author

This fixes a bug in which a reply to a status on a blocked book might still appear in a timeline, but I gotta say I just hit on that by accident. I don't think it meaningfully changes the performance of the query (which is what I was trying to do), but it's slightly better.

Running this against production, before:

 Bitmap Heap Scan on bookwyrm_user  (cost=907.88..308728.55 rows=3831 width=1477) (actual time=27.342..153.303 rows=29205 loops=1)                                                                      
   Recheck Cond: (local AND is_active)                                                                                                                                                                  
   Filter: ((NOT (ANY (id = (hashed SubPlan 1).col1))) AND (NOT (ANY (id = (hashed SubPlan 4).col1))) AND (NOT (ANY (id = (hashed SubPlan 3).col1))))                                                   
   Rows Removed by Filter: 1                                                                                                                                                                            
   Heap Blocks: exact=21303                                                                                                                                                                             
   ->  Bitmap Index Scan on bookwyrm_us_local_40fe61_idx  (cost=0.00..826.94 rows=30652 width=0) (actual time=4.870..4.871 rows=29206 loops=1)                                                          
         Index Cond: ((local = true) AND (is_active = true))                                                                                                                                            
   SubPlan 1                                                                                                                                                                                            
     ->  Nested Loop  (cost=0.70..16.74 rows=1 width=4) (actual time=0.027..0.029 rows=0 loops=1)                                                                                                       
           ->  Index Only Scan using userblocks_unique on bookwyrm_userblocks u1  (cost=0.28..8.29 rows=1 width=4) (actual time=0.027..0.027 rows=0 loops=1)                                            
                 Index Cond: (user_subject_id = 227768)                                                                                                                                                 
                 Heap Fetches: 0                                                                                                                                                                        
           ->  Index Only Scan using bookwyrm_user_pkey on bookwyrm_user u0  (cost=0.42..8.44 rows=1 width=4) (never executed)                                                                          
                 Index Cond: (id = u1.user_object_id)                                                                                                                                                   
                 Heap Fetches: 0                                                                                                                                                                        
   SubPlan 4                                                                                                                                                                                            
     ->  Nested Loop  (cost=4.66..63.21 rows=10 width=4) (actual time=0.489..0.492 rows=1 loops=1)                                                                                                      
           ->  Bitmap Heap Scan on bookwyrm_user_blocked_books u1_2  (cost=4.23..14.79 rows=10 width=4) (actual time=0.271..0.272 rows=1 loops=1)                                                       
                 Recheck Cond: (work_id = 6644)                                                                                                                                                         
                 Heap Blocks: exact=1                                                                                                                                                                   
                 ->  Bitmap Index Scan on bookwyrm_user_blocked_books_work_id_b838f8eb  (cost=0.00..4.23 rows=10 width=0) (actual time=0.011..0.012 rows=1 loops=1)                                     
                       Index Cond: (work_id = 6644)                                                                                                                                                     
           ->  Index Only Scan using bookwyrm_user_pkey on bookwyrm_user u0_1  (cost=0.42..4.84 rows=1 width=4) (actual time=0.024..0.024 rows=1 loops=1)                                               
                 Index Cond: (id = u1_2.user_id)                                                                                                                                                        
                 Heap Fetches: 0                                                                                                                                                                        
   SubPlan 3                                                                                                                                                                                            
     ->  Index Scan using bookwyrm_userblocks_user_object_id_ff33ba18 on bookwyrm_userblocks u1_1  (cost=0.28..8.29 rows=1 width=4) (actual time=0.103..0.104 rows=1 loops=1)                           
           Index Cond: (user_object_id = 227768)                                                                                                                                                        
 Planning Time: 2.861 ms                                                                                                                                                                                
 JIT:                                                                                                                                                                                                   
   Functions: 50                                                                                                                                                                                        
   Options: Inlining false, Optimization false, Expressions true, Deforming true
   Timing: Generation 2.182 ms (Deform 1.177 ms), Inlining 0.000 ms, Optimization 1.568 ms, Emission 17.173 ms, Total 20.923 ms
 Execution Time: 177.124 ms
(34 rows)

And after:

 Bitmap Heap Scan on bookwyrm_user  (cost=845.60..308666.28 rows=7663 width=1477) (actual time=20.220..121.201 rows=29205 loops=1)
   Recheck Cond: (local AND is_active)
   Filter: ((NOT (ANY (id = (hashed SubPlan 1).col1))) AND (id <> 179036) AND (NOT (ANY (id = (hashed SubPlan 3).col1))))
   Rows Removed by Filter: 1
   Heap Blocks: exact=21303
   ->  Bitmap Index Scan on bookwyrm_us_local_40fe61_idx  (cost=0.00..826.94 rows=30652 width=0) (actual time=3.246..3.247 rows=29210 loops=1)
         Index Cond: ((local = true) AND (is_active = true))
   SubPlan 1
     ->  Nested Loop  (cost=0.70..16.74 rows=1 width=4) (actual time=0.020..0.021 rows=0 loops=1)
           ->  Index Only Scan using userblocks_unique on bookwyrm_userblocks u1  (cost=0.28..8.29 rows=1 width=4) (actual time=0.019..0.019 rows=0 loops=1)
                 Index Cond: (user_subject_id = 227768)
                 Heap Fetches: 0
           ->  Index Only Scan using bookwyrm_user_pkey on bookwyrm_user u0  (cost=0.42..8.44 rows=1 width=4) (never executed)
                 Index Cond: (id = u1.user_object_id)
                 Heap Fetches: 0
   SubPlan 3
     ->  Index Scan using bookwyrm_userblocks_user_object_id_ff33ba18 on bookwyrm_userblocks u1_1  (cost=0.28..8.29 rows=1 width=4) (actual time=0.178..0.179 rows=1 loops=1)
           Index Cond: (user_object_id = 227768)
 Planning Time: 0.406 ms
 JIT:
   Functions: 34
   Options: Inlining false, Optimization false, Expressions true, Deforming true
   Timing: Generation 1.326 ms (Deform 0.692 ms), Inlining 0.000 ms, Optimization 1.013 ms, Emission 12.738 ms, Total 15.077 ms
 Execution Time: 123.770 ms
(24 rows)

@mouse-reeve mouse-reeve added the fix To label PRs that fix bugs label Jul 20, 2026
@hughrun

hughrun commented Jul 20, 2026

Copy link
Copy Markdown
Member

Looks good. Easier to read TBH, apart from the thread_book_ids comprehension, which makes my head hurt.

@mouse-reeve
mouse-reeve merged commit d637501 into main Jul 20, 2026
9 checks passed
@mouse-reeve
mouse-reeve deleted the blocked-query branch July 20, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix To label PRs that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants