mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 07:22:24 -05:00 
			
		
		
		
	start adding preloading support
This commit is contained in:
		
					parent
					
						
							
								6210ea33ee
							
						
					
				
			
			
				commit
				
					
						b3c9bfde18
					
				
			
		
					 7 changed files with 255 additions and 79 deletions
				
			
		|  | @ -25,6 +25,7 @@ import ( | |||
| 	statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/gtserror" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/log" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/paging" | ||||
| ) | ||||
| 
 | ||||
|  | @ -90,3 +91,35 @@ func (p *Processor) HomeTimelineGet( | |||
| 		}, | ||||
| 	) | ||||
| } | ||||
| 
 | ||||
| // preloadHomeTimeline will ensure that the timeline | ||||
| // cache for home owned by given account is preloaded. | ||||
| func (p *Processor) preloadHomeTimeline( | ||||
| 	ctx context.Context, | ||||
| 	account *gtsmodel.Account, | ||||
| ) error { | ||||
| 
 | ||||
| 	// Get (and so, create) home timeline cache for account ID. | ||||
| 	timeline := p.state.Caches.Timelines.Home.MustGet(account.ID) | ||||
| 
 | ||||
| 	// Preload timeline with funcs. | ||||
| 	n, err := timeline.Preload(ctx, | ||||
| 
 | ||||
| 		// Database load function. | ||||
| 		func(page *paging.Page) ([]*gtsmodel.Status, error) { | ||||
| 			return p.state.DB.GetHomeTimeline(ctx, account.ID, page) | ||||
| 		}, | ||||
| 
 | ||||
| 		// Status filtering function. | ||||
| 		func(status *gtsmodel.Status) (bool, error) { | ||||
| 			ok, err := p.visFilter.StatusHomeTimelineable(ctx, account, status) | ||||
| 			return !ok, err | ||||
| 		}, | ||||
| 	) | ||||
| 	if err != nil { | ||||
| 		return gtserror.Newf("error preloading home timeline %s: %w", account.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	log.Infof(ctx, "%s: preloaded %d", account.Username, n) | ||||
| 	return nil | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue