@@ -8,28 +8,22 @@ import (
88 "github.com/jellydator/ttlcache/v3"
99 "golang.org/x/sync/singleflight"
1010
11- "github.com/e2b-dev/infra/packages/db/queries "
11+ "github.com/e2b-dev/infra/packages/api/internal/ db/types "
1212)
1313
1414const (
1515 authInfoExpiration = 5 * time .Minute
1616 refreshInterval = 1 * time .Minute
1717)
1818
19- type AuthTeamInfo struct {
20- Team * queries.Team
21- Tier * queries.Tier
22- }
23-
2419type TeamInfo struct {
25- team * queries.Team
26- tier * queries.Tier
20+ team * types.Team
2721
2822 lastRefresh time.Time
2923 once singleflight.Group
3024}
3125
32- type DataCallback = func (ctx context.Context , key string ) (* queries .Team , * queries. Tier , error )
26+ type DataCallback = func (ctx context.Context , key string ) (* types .Team , error )
3327
3428type TeamAuthCache struct {
3529 cache * ttlcache.Cache [string , * TeamInfo ]
@@ -45,21 +39,21 @@ func NewTeamAuthCache() *TeamAuthCache {
4539}
4640
4741// TODO: save blocked teams to cache as well, handle the condition in the GetOrSet method
48- func (c * TeamAuthCache ) GetOrSet (ctx context.Context , key string , dataCallback DataCallback ) (team * queries .Team , tier * queries. Tier , err error ) {
42+ func (c * TeamAuthCache ) GetOrSet (ctx context.Context , key string , dataCallback DataCallback ) (team * types .Team , err error ) {
4943 var item * ttlcache.Item [string , * TeamInfo ]
5044 var templateInfo * TeamInfo
5145
5246 item = c .cache .Get (key )
5347 if item == nil {
54- team , tier , err = dataCallback (ctx , key )
48+ team , err = dataCallback (ctx , key )
5549 if err != nil {
56- return nil , nil , fmt .Errorf ("error while getting the team: %w" , err )
50+ return nil , fmt .Errorf ("error while getting the team: %w" , err )
5751 }
5852
59- templateInfo = & TeamInfo {team : team , tier : tier , lastRefresh : time .Now ()}
53+ templateInfo = & TeamInfo {team : team , lastRefresh : time .Now ()}
6054 c .cache .Set (key , templateInfo , authInfoExpiration )
6155
62- return team , tier , nil
56+ return team , nil
6357 }
6458
6559 templateInfo = item .Value ()
@@ -70,20 +64,20 @@ func (c *TeamAuthCache) GetOrSet(ctx context.Context, key string, dataCallback D
7064 })
7165 }
7266
73- return templateInfo .team , templateInfo . tier , nil
67+ return templateInfo .team , nil
7468}
7569
7670// Refresh refreshes the cache for the given team ID.
7771func (c * TeamAuthCache ) Refresh (key string , dataCallback DataCallback ) {
7872 ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
7973 defer cancel ()
8074
81- team , tier , err := dataCallback (ctx , key )
75+ team , err := dataCallback (ctx , key )
8276 if err != nil {
8377 c .cache .Delete (key )
8478
8579 return
8680 }
8781
88- c .cache .Set (key , & TeamInfo {team : team , tier : tier , lastRefresh : time .Now ()}, authInfoExpiration )
82+ c .cache .Set (key , & TeamInfo {team : team , lastRefresh : time .Now ()}, authInfoExpiration )
8983}
0 commit comments