mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 17:32:25 -05:00 
			
		
		
		
	[performance] cached oauth database types (#2838)
* update token + client code to use struct caches * add code comments * slight tweak to default mem ratios * fix envparsing * add appropriate invalidate hooks * update the tokenstore sweeping function to rely on caches * update to use PutClient() * add ClientID to list of token struct indices
This commit is contained in:
		
					parent
					
						
							
								8b30709791
							
						
					
				
			
			
				commit
				
					
						f79d50b9b2
					
				
			
		
					 18 changed files with 428 additions and 67 deletions
				
			
		|  | @ -27,11 +27,11 @@ import ( | |||
| ) | ||||
| 
 | ||||
| type clientStore struct { | ||||
| 	db db.Basic | ||||
| 	db db.DB | ||||
| } | ||||
| 
 | ||||
| // NewClientStore returns an implementation of the oauth2 ClientStore interface, using the given db as a storage backend. | ||||
| func NewClientStore(db db.Basic) oauth2.ClientStore { | ||||
| func NewClientStore(db db.DB) oauth2.ClientStore { | ||||
| 	pts := &clientStore{ | ||||
| 		db: db, | ||||
| 	} | ||||
|  | @ -39,26 +39,27 @@ func NewClientStore(db db.Basic) oauth2.ClientStore { | |||
| } | ||||
| 
 | ||||
| func (cs *clientStore) GetByID(ctx context.Context, clientID string) (oauth2.ClientInfo, error) { | ||||
| 	poc := >smodel.Client{} | ||||
| 	if err := cs.db.GetByID(ctx, clientID, poc); err != nil { | ||||
| 	client, err := cs.db.GetClientByID(ctx, clientID) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return models.New(poc.ID, poc.Secret, poc.Domain, poc.UserID), nil | ||||
| 	return models.New( | ||||
| 		client.ID, | ||||
| 		client.Secret, | ||||
| 		client.Domain, | ||||
| 		client.UserID, | ||||
| 	), nil | ||||
| } | ||||
| 
 | ||||
| func (cs *clientStore) Set(ctx context.Context, id string, cli oauth2.ClientInfo) error { | ||||
| 	poc := >smodel.Client{ | ||||
| 	return cs.db.PutClient(ctx, >smodel.Client{ | ||||
| 		ID:     cli.GetID(), | ||||
| 		Secret: cli.GetSecret(), | ||||
| 		Domain: cli.GetDomain(), | ||||
| 		UserID: cli.GetUserID(), | ||||
| 	} | ||||
| 	return cs.db.Put(ctx, poc) | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func (cs *clientStore) Delete(ctx context.Context, id string) error { | ||||
| 	poc := >smodel.Client{ | ||||
| 		ID: id, | ||||
| 	} | ||||
| 	return cs.db.DeleteByID(ctx, id, poc) | ||||
| 	return cs.db.DeleteClientByID(ctx, id) | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue