From 63a7f8bef0df1127a899f1cf4ea1c7b99819b87d Mon Sep 17 00:00:00 2001 From: Tobeyw Date: Thu, 13 Jun 2024 14:00:38 +0800 Subject: [PATCH 1/2] fix limit for job interface --- neo3fura_http/biz/api/src.GetInfoByNFT.go | 19 +++++++++-------- .../biz/job/job.GetDailyTransactions.go | 17 +++++++++------ .../biz/job/job.GetHourlyTransactions.go | 19 +++++++++++------ neo3fura_http/biz/job/job.GetNewAddresses.go | 21 ++++++++++++++----- 4 files changed, 50 insertions(+), 26 deletions(-) diff --git a/neo3fura_http/biz/api/src.GetInfoByNFT.go b/neo3fura_http/biz/api/src.GetInfoByNFT.go index 25ce054d..7dad9ec9 100644 --- a/neo3fura_http/biz/api/src.GetInfoByNFT.go +++ b/neo3fura_http/biz/api/src.GetInfoByNFT.go @@ -2,19 +2,20 @@ package api import ( "encoding/json" - "fmt" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" "io/ioutil" "math/big" - "neo3fura_http/lib/type/Contract" - "neo3fura_http/lib/type/h160" - "neo3fura_http/lib/type/strval" - "neo3fura_http/var/stderr" "net/http" "os" "strconv" "time" + + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + + "neo3fura_http/lib/type/Contract" + "neo3fura_http/lib/type/h160" + "neo3fura_http/lib/type/strval" + "neo3fura_http/var/stderr" ) func (me *T) GetInfoByNFT(args struct { @@ -246,7 +247,7 @@ func GetNNSByAddress(address string) (string, string, error) { } else if rt == "test" { url = "https://megaoasis.ngd.network:8889/profile/get?address=" //test } - fmt.Println(url + address) + //fmt.Println(url + address) resp, err := http.Get(url + address) if err != nil { return "", "", err @@ -254,7 +255,7 @@ func GetNNSByAddress(address string) (string, string, error) { defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) var nns, userName string - fmt.Println("body:", string(body)) + //fmt.Println("body:", string(body)) if string(body) != "" && string(body) != "null" { var data map[string]interface{} err = json.Unmarshal(body, &data) diff --git a/neo3fura_http/biz/job/job.GetDailyTransactions.go b/neo3fura_http/biz/job/job.GetDailyTransactions.go index dcf2911a..c72c4e7d 100644 --- a/neo3fura_http/biz/job/job.GetDailyTransactions.go +++ b/neo3fura_http/biz/job/job.GetDailyTransactions.go @@ -21,25 +21,30 @@ func (me T) GetDailyTransactions() error { if err != nil { return err } - r1, _, err := me.Client.QueryAll(struct { + r1, 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: "Transaction", Index: "GetDailyTransactions", Sort: bson.M{}, - Filter: bson.M{"blocktime": bson.M{"$gt": r0["blocktime"].(int64) - 3600*24*1000}}, - Query: []string{}, + Filter: bson.M{}, + Pipeline: []bson.M{ + bson.M{"$match": bson.M{"blocktime": bson.M{"$gt": r0["blocktime"].(int64) - 3600*24*1000}}}, + bson.M{"$group": bson.M{"_id": "$_id"}}, + bson.M{"$count": "count"}, + }, + Query: []string{}, }, ret) + if err != nil { return err } - data := bson.M{"DailyTransactions": len(r1), "insertTime": r0["blocktime"]} + data := bson.M{"DailyTransactions": r1[0]["count"], "insertTime": r0["blocktime"]} _, err = me.Client.SaveJob(struct { Collection string Data bson.M diff --git a/neo3fura_http/biz/job/job.GetHourlyTransactions.go b/neo3fura_http/biz/job/job.GetHourlyTransactions.go index 59d68620..c6ec274d 100644 --- a/neo3fura_http/biz/job/job.GetHourlyTransactions.go +++ b/neo3fura_http/biz/job/job.GetHourlyTransactions.go @@ -2,6 +2,7 @@ package job import ( "encoding/json" + "go.mongodb.org/mongo-driver/bson" ) @@ -20,25 +21,31 @@ func (me T) GetHourlyTransactions() error { if err != nil { return err } - r1, _, err := me.Client.QueryAll(struct { + + r1, 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: "Transaction", Index: "GetHourlyTransactions", Sort: bson.M{}, - Filter: bson.M{"blocktime": bson.M{"$gt": r0["blocktime"].(int64) - 3600*1000}}, - Query: []string{}, + Filter: bson.M{}, + Pipeline: []bson.M{ + bson.M{"$match": bson.M{"blocktime": bson.M{"$gt": r0["blocktime"].(int64) - 3600*1000}}}, + bson.M{"$group": bson.M{"_id": "$_id"}}, + bson.M{"$count": "count"}, + }, + Query: []string{}, }, ret) + if err != nil { return err } - data := bson.M{"HourlyTransactions": len(r1)} + data := bson.M{"HourlyTransactions": r1[0]["count"], "insertTime": r0["blocktime"].(int64) - 3600*1000} _, err = me.Client.SaveJob(struct { Collection string Data bson.M diff --git a/neo3fura_http/biz/job/job.GetNewAddresses.go b/neo3fura_http/biz/job/job.GetNewAddresses.go index 6cf12bda..7d5cceca 100644 --- a/neo3fura_http/biz/job/job.GetNewAddresses.go +++ b/neo3fura_http/biz/job/job.GetNewAddresses.go @@ -22,20 +22,31 @@ func (me T) GetNewAddresses() error { return err } - _, count, err := me.Client.QueryAll(struct { + r1, 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: "Address", Index: "GetNewAddresses", Filter: bson.M{"firstusetime": bson.M{"$gt": r0["blocktime"].(int64) - 3600*24*1000}}}, ret) + }{ + Collection: "Address", + Index: "GetNewAddresses", + Sort: bson.M{}, + Filter: bson.M{}, + Pipeline: []bson.M{ + bson.M{"$match": bson.M{"firstusetime": bson.M{"$gt": r0["blocktime"].(int64) - 3600*24*1000}}}, + bson.M{"$group": bson.M{"_id": "$_id"}}, + bson.M{"$count": "count"}, + }, + Query: []string{}, + }, ret) + if err != nil { return err } - data := bson.M{"NewAddresses": count, "insertTime": r0["blocktime"]} + data := bson.M{"NewAddresses": r1[0]["count"], "insertTime": r0["blocktime"]} _, err = me.Client.SaveJob(struct { Collection string Data bson.M From 5e7a1383d0ea00eef4c6d85d0aec8a28756555ed Mon Sep 17 00:00:00 2001 From: Tobeyw Date: Thu, 13 Jun 2024 14:12:37 +0800 Subject: [PATCH 2/2] add test log --- neo3fura_http/biz/watch/watch.GetFirstEventByTransactionHash.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neo3fura_http/biz/watch/watch.GetFirstEventByTransactionHash.go b/neo3fura_http/biz/watch/watch.GetFirstEventByTransactionHash.go index 741e1149..bf0f9240 100644 --- a/neo3fura_http/biz/watch/watch.GetFirstEventByTransactionHash.go +++ b/neo3fura_http/biz/watch/watch.GetFirstEventByTransactionHash.go @@ -3,6 +3,7 @@ package watch import ( "context" "encoding/json" + "fmt" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -61,6 +62,7 @@ func (me *T) GetFirstEventByTransactionHash() error { log2.Fatalf("Query Execution error:%v", err) } if len(r1) > 0 && r1["vmstate"] != nil && r1["vmstate"] != "" { + fmt.Println("TEST", r1["vmstate"], r2["vmstate"]) r2["vmstate"] = r1["vmstate"] _, err = me.Client.SaveJob(struct { Collection string