Skip to content

Commit e508567

Browse files
committed
Review
1 parent 60514d0 commit e508567

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

mongo/document/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Base struct {
1313
UpdatedAt time.Time `bson:"updated_at" json:"updated_at"`
1414
}
1515

16-
func (d *Base) IsPersisted() bool {
16+
func (d Base) IsPersisted() bool {
1717
return !d.CreatedAt.IsZero()
1818
}
1919

@@ -45,6 +45,6 @@ func (d *Base) destroy(ctx context.Context, collection string) error {
4545
return ReallyDestroy(ctx, collection, d)
4646
}
4747

48-
func (d *Base) Validate(ctx context.Context) *ValidationErrors {
48+
func (d Base) Validate(ctx context.Context) *ValidationErrors {
4949
return nil
5050
}

mongo/document/document.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type scopable interface {
3131
scope(bson.M) bson.M
3232
}
3333

34-
var _ scopable = &Base{}
35-
var _ scopable = &Paranoid{}
34+
var _ scopable = Base{}
35+
var _ scopable = Paranoid{}
3636

3737
type destroyable interface {
3838
destroy(ctx context.Context, collectionName string) error
@@ -49,7 +49,7 @@ type Validable interface {
4949
Validate(ctx context.Context) *ValidationErrors
5050
}
5151

52-
var _ Validable = &Base{}
52+
var _ Validable = Base{}
5353

5454
// Create inser the document in the database, returns an error if document already exists and set CreatedAt timestamp
5555
func Create(ctx context.Context, collectionName string, doc document) error {
@@ -236,24 +236,22 @@ func Update(ctx context.Context, collectionName string, update bson.M, doc docum
236236
}
237237

238238
func EnsureParanoidIndices(ctx context.Context, collectionNames ...string) {
239-
go func() {
240-
log := logger.Get(ctx)
241-
242-
for _, collectionName := range collectionNames {
243-
log := logger.Get(ctx).WithFields(logrus.Fields{
244-
"init": "setup-indices",
245-
"collection": collectionName,
246-
})
247-
ctx := logger.ToCtx(ctx, log)
248-
log.Info("Setup the MongoDB index")
249-
250-
c := mongo.Session(log).Clone().DB("").C(collectionName)
251-
defer c.Database.Session.Close()
252-
err := c.EnsureIndexKey("deleted_at")
253-
if err != nil {
254-
log.WithError(err).Error("fail to setup the deleted_at index")
255-
return
256-
}
239+
log := logger.Get(ctx)
240+
241+
for _, collectionName := range collectionNames {
242+
log = logger.Get(ctx).WithFields(logrus.Fields{
243+
"init": "setup-indices",
244+
"collection": collectionName,
245+
})
246+
ctx = logger.ToCtx(ctx, log)
247+
log.Info("Setup the MongoDB index")
248+
249+
c := mongo.Session(log).Clone().DB("").C(collectionName)
250+
defer c.Database.Session.Close()
251+
err := c.EnsureIndexKey("deleted_at")
252+
if err != nil {
253+
log.WithError(err).Error("fail to setup the deleted_at index")
254+
continue
257255
}
258-
}()
256+
}
259257
}

mongo/document/paranoid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (d *Paranoid) setDeletedAt(t time.Time) {
2020
d.DeletedAt = &t
2121
}
2222

23-
func (d *Paranoid) scope(query bson.M) bson.M {
23+
func (d Paranoid) scope(query bson.M) bson.M {
2424
if _, ok := query["deleted_at"]; !ok {
2525
query["deleted_at"] = nil
2626
}

0 commit comments

Comments
 (0)