diff --git a/neo3fura_http/biz/job/job.GetHoldersByContractHash.go b/neo3fura_http/biz/job/job.GetHoldersByContractHash.go index 98811dd..db8d9e3 100644 --- a/neo3fura_http/biz/job/job.GetHoldersByContractHash.go +++ b/neo3fura_http/biz/job/job.GetHoldersByContractHash.go @@ -10,53 +10,28 @@ func (me T) GetHoldersByContractHash() error { message := make(json.RawMessage, 0) ret := &message data := make([]bson.M, 0) - r1, _, err := me.Client.QueryAll(struct { + + r0, err := me.Client.QueryAggregate(struct { Collection string Index string Sort bson.M Filter bson.M + Pipeline []bson.M Query []string - Limit int64 - Skip int64 }{ - Collection: "Asset", + Collection: "Address-Asset", Index: "GetHoldersByContractHash", Sort: bson.M{}, Filter: bson.M{}, - Query: []string{}, + Pipeline: []bson.M{ + bson.M{"$match": bson.M{"balance": bson.M{"$gt": 0}}}, + bson.M{"$group": bson.M{"_id": "$asset", "count": bson.M{"$sum": 1}}}, + }, + Query: []string{}, }, ret) - if err != nil { - return err - } - for _, item := range r1 { - holders, count, err := me.Client.QueryAll(struct { - Collection string - Index string - Sort bson.M - Filter bson.M - Query []string - Limit int64 - Skip int64 - }{ - Collection: "Address-Asset", - Index: "GetHoldersByContractHash", - Sort: bson.M{"balance": -1}, - Filter: bson.M{"asset": item["hash"], "balance": bson.M{"$gt": 0}}, - Query: []string{}, - Limit: int64(1000), - }, ret) - if err != nil { - return err - } - f := make(map[string]interface{}) - count = 0 - for _, holder := range holders { - f[holder["address"].(string)] = 1 - } - for _, _ = range f { - count = count + 1 - } - data = append(data, bson.M{item["hash"].(string): count}) + + for _, item := range r0 { + data = append(data, bson.M{item["_id"].(string): item["count"]}) } _, err = me.Client.SaveJob(struct { Collection string diff --git a/neo3fura_http/lib/cli/src.go b/neo3fura_http/lib/cli/src.go index 6218fb4..1cac400 100644 --- a/neo3fura_http/lib/cli/src.go +++ b/neo3fura_http/lib/cli/src.go @@ -339,12 +339,11 @@ func (me *T) QueryAggregate(args struct { Pipeline []bson.M Query []string }, ret *json.RawMessage) ([]map[string]interface{}, error) { - for _, v := range args.Pipeline { limit := v["$limit"] if limit != nil { if limit.(int64) == 0 { - v["$limit"] = consts.DefaultLimit + // v["$limit"] = consts.DefaultLimit } if limit.(int64) > consts.MaxLimit { v["$limit"] = consts.MaxLimit diff --git a/neo3fura_http/lib/type/consts/src.go b/neo3fura_http/lib/type/consts/src.go index 98d20bc..e942d17 100644 --- a/neo3fura_http/lib/type/consts/src.go +++ b/neo3fura_http/lib/type/consts/src.go @@ -7,5 +7,5 @@ const ( NEO = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5" GAS = "0xd2a4cff31913016155e38e474a2c06d08be276cf" DefaultLimit = 20 - MaxLimit = 1000 + MaxLimit = 2000 )