From f79d50b9b26590b6d2468aeb41f0846272e08d1a Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:22:21 +0100 Subject: [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 --- internal/oauth/clientstore.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'internal/oauth/clientstore.go') diff --git a/internal/oauth/clientstore.go b/internal/oauth/clientstore.go index 5bb600e70..bddb30b1b 100644 --- a/internal/oauth/clientstore.go +++ b/internal/oauth/clientstore.go @@ -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) } -- cgit v1.2.3