Skip to content

Commit 5537a1c

Browse files
committed
chore: ctx refactor to keep up with main
1 parent 6085c0e commit 5537a1c

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

db/postgres/guide.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ func GetGuideByID(ctx context.Context, guideID string) *Guide {
4949
return guide.(*Guide)
5050
}
5151

52-
return GetGuideByIDNoCache(guideID, ctx)
52+
return GetGuideByIDNoCache(ctx, guideID)
5353
}
5454

55-
func GetGuideByIDNoCache(guideID string, ctx *context.Context) *Guide {
55+
func GetGuideByIDNoCache(ctx context.Context, guideID string) *Guide {
5656
var guide Guide
5757
DBCtx(ctx).Preload("Tags").Find(&guide, "id = ?", guideID)
5858

@@ -159,39 +159,39 @@ func GetUserGuides(ctx context.Context, userID string) []Guide {
159159
return guides
160160
}
161161

162-
func ClearGuideTags(guideID string, ctx *context.Context) error {
162+
func ClearGuideTags(ctx context.Context, guideID string) error {
163163
r := DBCtx(ctx).Where("guide_id = ?", guideID).Delete(&GuideTag{})
164164
return r.Error
165165
}
166166

167-
func SetGuideTags(guideID string, tagIDs []string, ctx *context.Context) error {
167+
func SetGuideTags(ctx context.Context, guideID string, tagIDs []string) error {
168168
for _, tag := range tagIDs {
169-
err := AddGuideTag(guideID, tag, ctx)
169+
err := AddGuideTag(ctx, guideID, tag)
170170
if err != nil {
171171
return err
172172
}
173173
}
174174
return nil
175175
}
176176

177-
func ResetGuideTags(guideID string, tagIDs []string, ctx *context.Context) error {
178-
err := ClearGuideTags(guideID, ctx)
177+
func ResetGuideTags(ctx context.Context, guideID string, tagIDs []string) error {
178+
err := ClearGuideTags(ctx, guideID)
179179
if err != nil {
180180
return err
181181
}
182-
err = SetGuideTags(guideID, tagIDs, ctx)
182+
err = SetGuideTags(ctx, guideID, tagIDs)
183183
if err != nil {
184184
return err
185185
}
186186
return nil
187187
}
188188

189-
func AddGuideTag(guideID string, tagID string, ctx *context.Context) error {
189+
func AddGuideTag(ctx context.Context, guideID string, tagID string) error {
190190
r := DBCtx(ctx).Create(&GuideTag{GuideID: guideID, TagID: tagID})
191191
return r.Error
192192
}
193193

194-
func RemoveGuideTag(guideID string, tagID string, ctx *context.Context) error {
194+
func RemoveGuideTag(ctx context.Context, guideID string, tagID string) error {
195195
r := DBCtx(ctx).Delete(&GuideTag{GuideID: guideID, TagID: tagID})
196196
return r.Error
197197
}

db/postgres/mod.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ func GetModByID(ctx context.Context, modID string) *Mod {
2121
return mod.(*Mod)
2222
}
2323

24-
return GetModByIDNoCache(modID, ctx)
24+
return GetModByIDNoCache(ctx, modID)
2525
}
2626

27-
func GetModByIDNoCache(modID string, ctx *context.Context) *Mod {
27+
func GetModByIDNoCache(ctx context.Context, modID string) *Mod {
2828
var mod Mod
2929
DBCtx(ctx).Preload("Tags").Find(&mod, "id = ?", modID)
3030

@@ -286,34 +286,34 @@ func ClearModTags(modID string, ctx *context.Context) error {
286286
return r.Error
287287
}
288288

289-
func SetModTags(modID string, tagIDs []string, ctx *context.Context) error {
289+
func SetModTags(ctx context.Context, modID string, tagIDs []string) error {
290290
for _, tag := range tagIDs {
291-
err := AddModTag(modID, tag, ctx)
291+
err := AddModTag(ctx, modID, tag)
292292
if err != nil {
293293
return err
294294
}
295295
}
296296
return nil
297297
}
298298

299-
func ResetModTags(modID string, tagIDs []string, ctx *context.Context) error {
300-
err := ClearModTags(modID, ctx)
299+
func ResetModTags(ctx context.Context, modID string, tagIDs []string) error {
300+
err := ClearModTags(ctx, modID)
301301
if err != nil {
302302
return err
303303
}
304-
err = SetModTags(modID, tagIDs, ctx)
304+
err = SetModTags(ctx, modID, tagIDs)
305305
if err != nil {
306306
return err
307307
}
308308
return nil
309309
}
310310

311-
func AddModTag(modID string, tagID string, ctx *context.Context) error {
311+
func AddModTag(ctx context.Context, modID string, tagID string) error {
312312
r := DBCtx(ctx).Create(&ModTag{ModID: modID, TagID: tagID})
313313
return r.Error
314314
}
315315

316-
func RemoveModTag(modID string, tagID string, ctx *context.Context) error {
316+
func RemoveModTag(ctx context.Context, modID string, tagID string) error {
317317
r := DBCtx(ctx).Delete(&ModTag{ModID: modID, TagID: tagID})
318318
return r.Error
319319
}

db/postgres/tags.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func ValidateTagName(tag string) error {
3232
return nil
3333
}
3434

35-
func CreateTag(tag *Tag, ctx *context.Context, ratelimit bool) (*Tag, error) {
35+
func CreateTag(ctx context.Context, tag *Tag, ratelimit bool) (*Tag, error) {
3636
err := ValidateTagName(tag.Name)
3737
if err != nil {
3838
return nil, err
3939
}
4040

41-
if GetTagByName(tag.Name, ctx) != nil {
41+
if GetTagByName(ctx, tag.Name) != nil {
4242
return nil, fmt.Errorf("Tag %v already exists", tag.Name)
4343
}
4444

@@ -74,7 +74,7 @@ func CreateTag(tag *Tag, ctx *context.Context, ratelimit bool) (*Tag, error) {
7474
return tag, nil
7575
}
7676

77-
func GetTagByName(tagName string, ctx *context.Context) *Tag {
77+
func GetTagByName(ctx context.Context, tagName string) *Tag {
7878
cacheKey := "GetTagByName_" + tagName
7979

8080
if tag, ok := dbCache.Get(cacheKey); ok {
@@ -93,7 +93,7 @@ func GetTagByName(tagName string, ctx *context.Context) *Tag {
9393
return &tag
9494
}
9595

96-
func GetTagByID(tagID string, ctx *context.Context) *Tag {
96+
func GetTagByID(ctx context.Context, tagID string) *Tag {
9797
cacheKey := "GetTagById_" + tagID
9898

9999
if tag, ok := dbCache.Get(cacheKey); ok {
@@ -112,7 +112,7 @@ func GetTagByID(tagID string, ctx *context.Context) *Tag {
112112
return &tag
113113
}
114114

115-
func GetTags(ctx *context.Context, filter *generated.TagFilter) []Tag {
115+
func GetTags(ctx context.Context, filter *generated.TagFilter) []Tag {
116116
cacheKey := ""
117117
hash, err := hashstructure.Hash(filter, hashstructure.FormatV2, nil)
118118
if err == nil {

gql/directive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func canEditAnnouncements(ctx context.Context, obj interface{}, next graphql.Res
228228
func canManageTags(ctx context.Context, obj interface{}, next graphql.Resolver) (res interface{}, err error) {
229229
user := ctx.Value(postgres.UserKey{}).(*postgres.User)
230230

231-
if user.Has(auth.RoleManageTags, &ctx) {
231+
if user.Has(ctx, auth.RoleManageTags) {
232232
return next(ctx)
233233
}
234234

gql/resolver_guides.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ func (r *mutationResolver) CreateGuide(ctx context.Context, guide generated.NewG
4141
return nil, err
4242
}
4343

44-
err = postgres.SetGuideTags(resultGuide.ID, guide.TagIDs, &newCtx)
44+
err = postgres.SetGuideTags(newCtx, resultGuide.ID, guide.TagIDs)
4545

4646
if err != nil {
4747
return nil, err
4848
}
4949

5050
// Need to get the guide again to populate tags
51-
return DBGuideToGenerated(postgres.GetGuideByIDNoCache(resultGuide.ID, &newCtx)), nil
51+
return DBGuideToGenerated(postgres.GetGuideByIDNoCache(newCtx, resultGuide.ID)), nil
5252
}
5353

5454
func (r *mutationResolver) UpdateGuide(ctx context.Context, guideID string, guide generated.UpdateGuide) (*generated.Guide, error) {
@@ -60,12 +60,12 @@ func (r *mutationResolver) UpdateGuide(ctx context.Context, guideID string, guid
6060
return nil, errors.Wrap(err, "validation failed")
6161
}
6262

63-
err := postgres.ResetGuideTags(guideID, guide.TagIDs, &newCtx)
63+
err := postgres.ResetGuideTags(newCtx, guideID, guide.TagIDs)
6464
if err != nil {
6565
return nil, err
6666
}
6767

68-
dbGuide := postgres.GetGuideByIDNoCache(guideID, &newCtx)
68+
dbGuide := postgres.GetGuideByIDNoCache(newCtx, guideID)
6969

7070
if dbGuide == nil {
7171
return nil, errors.New("guide not found")

gql/resolver_mods.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ func (r *mutationResolver) CreateMod(ctx context.Context, mod generated.NewMod)
8383
}
8484
}
8585

86-
err = postgres.SetModTags(resultMod.ID, mod.TagIDs, &newCtx)
86+
err = postgres.SetModTags(newCtx, resultMod.ID, mod.TagIDs)
8787

8888
if err != nil {
8989
return nil, err
9090
}
9191

9292
// Need to get the mod again to populate tags
93-
return DBModToGenerated(postgres.GetModByIDNoCache(resultMod.ID, &newCtx)), nil
93+
return DBModToGenerated(postgres.GetModByIDNoCache(newCtx, resultMod.ID)), nil
9494
}
9595

9696
func (r *mutationResolver) UpdateMod(ctx context.Context, modID string, mod generated.UpdateMod) (*generated.Mod, error) {
@@ -102,13 +102,13 @@ func (r *mutationResolver) UpdateMod(ctx context.Context, modID string, mod gene
102102
return nil, errors.Wrap(err, "validation failed")
103103
}
104104

105-
err := postgres.ResetModTags(modID, mod.TagIDs, &newCtx)
105+
err := postgres.ResetModTags(newCtx, modID, mod.TagIDs)
106106

107107
if err != nil {
108108
return nil, err
109109
}
110110

111-
dbMod := postgres.GetModByIDNoCache(modID, &newCtx)
111+
dbMod := postgres.GetModByIDNoCache(newCtx, modID)
112112

113113
if dbMod == nil {
114114
return nil, errors.New("mod not found")

gql/resolver_tags.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (r *mutationResolver) CreateTag(ctx context.Context, tagName string) (*gene
1717
Name: tagName,
1818
}
1919

20-
resultTag, err := postgres.CreateTag(dbTag, &newCtx, true)
20+
resultTag, err := postgres.CreateTag(newCtx, dbTag, true)
2121
if err != nil {
2222
return nil, err
2323
}
@@ -35,7 +35,7 @@ func (r *mutationResolver) CreateMultipleTags(ctx context.Context, tagNames []st
3535
Name: tagName,
3636
}
3737

38-
resultTag, err := postgres.CreateTag(dbTag, &newCtx, false)
38+
resultTag, err := postgres.CreateTag(newCtx, dbTag, false)
3939
if err != nil {
4040
return nil, err
4141
}
@@ -50,13 +50,13 @@ func (r *mutationResolver) DeleteTag(ctx context.Context, id string) (bool, erro
5050
wrapper, newCtx := WrapMutationTrace(ctx, "deleteTag")
5151
defer wrapper.end()
5252

53-
dbTag := postgres.GetTagByID(id, &newCtx)
53+
dbTag := postgres.GetTagByID(newCtx, id)
5454

5555
if dbTag == nil {
5656
return false, errors.New("Tag not found")
5757
}
5858

59-
postgres.Delete(&dbTag, &newCtx)
59+
postgres.Delete(newCtx, &dbTag)
6060

6161
return true, nil
6262
}
@@ -65,7 +65,7 @@ func (r *mutationResolver) UpdateTag(ctx context.Context, id string, newName str
6565
wrapper, newCtx := WrapMutationTrace(ctx, "updateTag")
6666
defer wrapper.end()
6767

68-
dbTag := postgres.GetTagByID(id, &newCtx)
68+
dbTag := postgres.GetTagByID(newCtx, id)
6969

7070
if dbTag == nil {
7171
return nil, errors.New("Tag not found")
@@ -78,7 +78,7 @@ func (r *mutationResolver) UpdateTag(ctx context.Context, id string, newName str
7878

7979
SetStringINNOE(&newName, &dbTag.Name)
8080

81-
postgres.Save(&dbTag, &newCtx)
81+
postgres.Save(newCtx, &dbTag)
8282

8383
return DBTagToGenerated(dbTag), nil
8484
}
@@ -87,7 +87,7 @@ func (r *queryResolver) GetTag(ctx context.Context, id string) (*generated.Tag,
8787
wrapper, newCtx := WrapQueryTrace(ctx, "getTag_"+id)
8888
defer wrapper.end()
8989

90-
tag := postgres.GetTagByID(id, &newCtx)
90+
tag := postgres.GetTagByID(newCtx, id)
9191

9292
return DBTagToGenerated(tag), nil
9393
}
@@ -97,7 +97,7 @@ func (r *queryResolver) GetTags(ctx context.Context, filter *generated.TagFilter
9797
defer wrapper.end()
9898

9999
insertFilterDefaults(filter)
100-
tags := postgres.GetTags(&newCtx, filter)
100+
tags := postgres.GetTags(newCtx, filter)
101101

102102
return DBTagsToGeneratedSlice(tags), nil
103103
}

0 commit comments

Comments
 (0)