Skip to content

Commit

Permalink
fix index tomox mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
nghiatomo committed Jun 22, 2020
1 parent f724dc7 commit 031db91
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 127 deletions.
17 changes: 1 addition & 16 deletions daos/lending_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ func NewLendingOrderDao(opts ...LendingOrderDaoOption) *LendingOrderDao {
}
}

index := mgo.Index{
Key: []string{"hash"},
Unique: true,
}

i1 := mgo.Index{
Key: []string{"userAddress"},
}
Expand All @@ -68,18 +63,8 @@ func NewLendingOrderDao(opts ...LendingOrderDaoOption) *LendingOrderDao {
i5 := mgo.Index{
Key: []string{"createdAt"},
}
indexes := []mgo.Index{}
indexes, err := db.Session.DB(dao.dbName).C(dao.collectionName).Indexes()
if err == nil {
if !existedIndex("index_lending_item_hash", indexes) {
err := db.Session.DB(dao.dbName).C(dao.collectionName).EnsureIndex(index)
if err != nil {
panic(err)
}
}
}

err = db.Session.DB(dao.dbName).C(dao.collectionName).EnsureIndex(i1)
err := db.Session.DB(dao.dbName).C(dao.collectionName).EnsureIndex(i1)
if err != nil {
panic(err)
}
Expand Down
42 changes: 0 additions & 42 deletions daos/lending_trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,10 @@ func NewLendingTradeDao() *LendingTradeDao {
dbName := app.Config.DBName
collection := "lending_trades"

i1 := mgo.Index{
Key: []string{"collateralToken"},
}

i2 := mgo.Index{
Key: []string{"lendingToken"},
}

i3 := mgo.Index{
Key: []string{"createdAt"},
}

i4 := mgo.Index{
Key: []string{"hash"},
Unique: true,
Sparse: true,
}

i5 := mgo.Index{
Key: []string{"borrowingHash"},
Sparse: true,
}

i6 := mgo.Index{
Key: []string{"investingHash"},
Sparse: true,
}

i7 := mgo.Index{
Key: []string{"createdAt", "status", "collateralToken", "lendingToken"},
}

indexes := []mgo.Index{}
indexes, err := db.Session.DB(dbName).C(collection).Indexes()
if err == nil {
if !existedIndex("index_lending_trade_hash", indexes) {
db.Session.DB(dbName).C(collection).EnsureIndex(i4)
}
}

db.Session.DB(dbName).C(collection).EnsureIndex(i1)
db.Session.DB(dbName).C(collection).EnsureIndex(i2)
db.Session.DB(dbName).C(collection).EnsureIndex(i3)
db.Session.DB(dbName).C(collection).EnsureIndex(i5)
db.Session.DB(dbName).C(collection).EnsureIndex(i6)
db.Session.DB(dbName).C(collection).EnsureIndex(i7)

return &LendingTradeDao{collection, dbName}
}
Expand Down
18 changes: 2 additions & 16 deletions daos/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ func NewOrderDao(opts ...OrderDaoOption) *OrderDao {
}
}

index := mgo.Index{
Key: []string{"hash"},
Unique: true,
}

i1 := mgo.Index{
Key: []string{"userAddress"},
}
Expand Down Expand Up @@ -90,18 +85,9 @@ func NewOrderDao(opts ...OrderDaoOption) *OrderDao {
i9 := mgo.Index{
Key: []string{"createdAt"},
}
indexes := []mgo.Index{}
indexes, err := db.Session.DB(dao.dbName).C(dao.collectionName).Indexes()
if err == nil {
if !existedIndex("index_order_hash", indexes) {
err := db.Session.DB(dao.dbName).C(dao.collectionName).EnsureIndex(index)
if err != nil {
panic(err)
}
}
}


err = db.Session.DB(dao.dbName).C(dao.collectionName).EnsureIndex(i1)
err := db.Session.DB(dao.dbName).C(dao.collectionName).EnsureIndex(i1)
if err != nil {
panic(err)
}
Expand Down
53 changes: 0 additions & 53 deletions daos/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,64 +23,11 @@ type TradeDao struct {
func NewTradeDao() *TradeDao {
dbName := app.Config.DBName
collection := "trades"

i1 := mgo.Index{
Key: []string{"baseToken"},
}

i2 := mgo.Index{
Key: []string{"quoteToken"},
}

i3 := mgo.Index{
Key: []string{"createdAt"},
}

i4 := mgo.Index{
Key: []string{"hash"},
Unique: true,
Sparse: true,
}

i5 := mgo.Index{
Key: []string{"makerOrderHash"},
Sparse: true,
}

i6 := mgo.Index{
Key: []string{"takerOrderHash"},
Sparse: true,
}

i7 := mgo.Index{
Key: []string{"createdAt", "status", "baseToken", "quoteToken"},
}

i8 := mgo.Index{
Key: []string{"pricepoint"},
Collation: &mgo.Collation{NumericOrdering: true, Locale: "en"},
}
i9 := mgo.Index{
Key: []string{"createdAt"},
Sparse: true,
}
indexes := []mgo.Index{}
indexes, err := db.Session.DB(dbName).C(collection).Indexes()
if err == nil {
if !existedIndex("index_trade_hash", indexes) {
db.Session.DB(dbName).C(collection).EnsureIndex(i4)
}
}

db.Session.DB(dbName).C(collection).EnsureIndex(i1)
db.Session.DB(dbName).C(collection).EnsureIndex(i2)
db.Session.DB(dbName).C(collection).EnsureIndex(i3)
db.Session.DB(dbName).C(collection).EnsureIndex(i5)
db.Session.DB(dbName).C(collection).EnsureIndex(i6)
db.Session.DB(dbName).C(collection).EnsureIndex(i7)
db.Session.DB(dbName).C(collection).EnsureIndex(i8)
db.Session.DB(dbName).C(collection).EnsureIndex(i9)

return &TradeDao{collection, dbName}
}

Expand Down

0 comments on commit 031db91

Please sign in to comment.