mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-30 19:22:25 -05:00 
			
		
		
		
	fix use of timeline.lastOrder, fix incorrect range functions used
This commit is contained in:
		
					parent
					
						
							
								8c09d0f20d
							
						
					
				
			
			
				commit
				
					
						8dfce9fa84
					
				
			
		
					 1 changed files with 13 additions and 10 deletions
				
			
		
							
								
								
									
										23
									
								
								internal/cache/timeline/status.go
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								internal/cache/timeline/status.go
									
										
									
									
										vendored
									
									
								
							|  | @ -247,14 +247,14 @@ type StatusTimeline struct { | ||||||
| 	idx_BoostOfID        *structr.Index //nolint:revive | 	idx_BoostOfID        *structr.Index //nolint:revive | ||||||
| 	idx_BoostOfAccountID *structr.Index //nolint:revive | 	idx_BoostOfAccountID *structr.Index //nolint:revive | ||||||
| 
 | 
 | ||||||
| 	// last stores the last fetched direction | 	// lasOrder stores the last fetched direction | ||||||
| 	// of the timeline, which in turn determines | 	// of the timeline, which in turn determines | ||||||
| 	// where we will next trim from in keeping the | 	// where we will next trim from in keeping the | ||||||
| 	// timeline underneath configured 'max'. | 	// timeline underneath configured 'max'. | ||||||
| 	// | 	// | ||||||
| 	// TODO: this could be more intelligent with | 	// TODO: this could be more intelligent with | ||||||
| 	// a sliding average. a problem for future kim! | 	// a sliding average. a problem for future kim! | ||||||
| 	last atomic.Pointer[structr.Direction] | 	lastOrder atomic.Pointer[structr.Direction] | ||||||
| 
 | 
 | ||||||
| 	// defines the 'maximum' count of | 	// defines the 'maximum' count of | ||||||
| 	// entries in the timeline that we | 	// entries in the timeline that we | ||||||
|  | @ -376,6 +376,9 @@ func (t *StatusTimeline) Load( | ||||||
| 		dir, | 		dir, | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
|  | 	// Mark last select order. | ||||||
|  | 	t.lastOrder.Store(&dir) | ||||||
|  | 
 | ||||||
| 	// We now reset the lo,hi values to | 	// We now reset the lo,hi values to | ||||||
| 	// represent the lowest and highest | 	// represent the lowest and highest | ||||||
| 	// index values of loaded statuses. | 	// index values of loaded statuses. | ||||||
|  | @ -742,7 +745,7 @@ func (t *StatusTimeline) UnprepareByStatusIDs(statusIDs ...string) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Unprepare all statuses stored under StatusMeta.ID. | 	// Unprepare all statuses stored under StatusMeta.ID. | ||||||
| 	for meta := range t.cache.RangeKeys(t.idx_ID, keys...) { | 	for meta := range t.cache.RangeKeysUnsafe(t.idx_ID, keys...) { | ||||||
| 		meta.prepared = nil | 		meta.prepared = nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -752,7 +755,7 @@ func (t *StatusTimeline) UnprepareByStatusIDs(statusIDs ...string) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Unprepare all statuses stored under StatusMeta.BoostOfID. | 	// Unprepare all statuses stored under StatusMeta.BoostOfID. | ||||||
| 	for meta := range t.cache.RangeKeys(t.idx_BoostOfID, keys...) { | 	for meta := range t.cache.RangeKeysUnsafe(t.idx_BoostOfID, keys...) { | ||||||
| 		meta.prepared = nil | 		meta.prepared = nil | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | @ -774,7 +777,7 @@ func (t *StatusTimeline) UnprepareByAccountIDs(accountIDs ...string) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Unprepare all statuses stored under StatusMeta.AccountID. | 	// Unprepare all statuses stored under StatusMeta.AccountID. | ||||||
| 	for meta := range t.cache.RangeKeys(t.idx_AccountID, keys...) { | 	for meta := range t.cache.RangeKeysUnsafe(t.idx_AccountID, keys...) { | ||||||
| 		meta.prepared = nil | 		meta.prepared = nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -784,7 +787,7 @@ func (t *StatusTimeline) UnprepareByAccountIDs(accountIDs ...string) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Unprepare all statuses stored under StatusMeta.BoostOfAccountID. | 	// Unprepare all statuses stored under StatusMeta.BoostOfAccountID. | ||||||
| 	for meta := range t.cache.RangeKeys(t.idx_BoostOfAccountID, keys...) { | 	for meta := range t.cache.RangeKeysUnsafe(t.idx_BoostOfAccountID, keys...) { | ||||||
| 		meta.prepared = nil | 		meta.prepared = nil | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | @ -810,10 +813,9 @@ func (t *StatusTimeline) Trim(threshold float64) { | ||||||
| 	// items as a percentage of max. | 	// items as a percentage of max. | ||||||
| 	max := threshold * float64(t.max) | 	max := threshold * float64(t.max) | ||||||
| 
 | 
 | ||||||
| 	// Try load the last fetched | 	// Load last fetched timeline ordering, | ||||||
| 	// timeline ordering, getting | 	// using the inverse value for trimming. | ||||||
| 	// the inverse value for trimming. | 	if p := t.lastOrder.Load(); p != nil { | ||||||
| 	if p := t.last.Load(); p != nil { |  | ||||||
| 		dir = !(*p) | 		dir = !(*p) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -865,6 +867,7 @@ func prepareStatuses( | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		// Append to return slice. | ||||||
| 		if meta.prepared != nil { | 		if meta.prepared != nil { | ||||||
| 			apiStatuses = append(apiStatuses, meta.prepared) | 			apiStatuses = append(apiStatuses, meta.prepared) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue