summaryrefslogtreecommitdiff
path: root/internal/oauth/clientstore.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-04-15 14:22:21 +0100
committerLibravatar GitHub <noreply@github.com>2024-04-15 14:22:21 +0100
commitf79d50b9b26590b6d2468aeb41f0846272e08d1a (patch)
tree196b9bfaf8ad6fce782c2130633cfb5c97cbd31a /internal/oauth/clientstore.go
parent[chore] Turn `accounts-registration-open` false by default (#2839) (diff)
downloadgotosocial-f79d50b9b26590b6d2468aeb41f0846272e08d1a.tar.xz
[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
Diffstat (limited to 'internal/oauth/clientstore.go')
-rw-r--r--internal/oauth/clientstore.go25
1 files changed, 13 insertions, 12 deletions
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 := &gtsmodel.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 := &gtsmodel.Client{
+ return cs.db.PutClient(ctx, &gtsmodel.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 := &gtsmodel.Client{
- ID: id,
- }
- return cs.db.DeleteByID(ctx, id, poc)
+ return cs.db.DeleteClientByID(ctx, id)
}