Commit 5a71daf7 authored by Cloud User's avatar Cloud User

http api expires

parent 046f8f6a
...@@ -2,8 +2,11 @@ package main ...@@ -2,8 +2,11 @@ package main
import ( import (
"sync" "sync"
"time"
pbUpstream "github.com/odysseus/odysseus-protocol/gen/proto/go/base/v1" pbUpstream "github.com/odysseus/odysseus-protocol/gen/proto/go/base/v1"
"github.com/hashicorp/golang-lru/v2/expirable"
) )
type apiQueryTxsForAddr struct { type apiQueryTxsForAddr struct {
...@@ -47,7 +50,8 @@ func callbackRes(res pbUpstream.TaskResponse) { ...@@ -47,7 +50,8 @@ func callbackRes(res pbUpstream.TaskResponse) {
if !resAsV.async { if !resAsV.async {
resAsV.res <- res resAsV.res <- res
} else { } else {
asyncmap.Store(res.TaskId, res) asyncmap.Add(res.TaskId, res)
//asyncmap.Store(res.TaskId, res)
} }
} }
} }
...@@ -55,18 +59,25 @@ func callbackRes(res pbUpstream.TaskResponse) { ...@@ -55,18 +59,25 @@ func callbackRes(res pbUpstream.TaskResponse) {
func getAsyncRes(uuid string) (pbUpstream.TaskResponse, bool) { func getAsyncRes(uuid string) (pbUpstream.TaskResponse, bool) {
if v, ok := asyncmap.LoadAndDelete(uuid); ok { return asyncmap.Get(uuid)
if resAsV, ok := v.(pbUpstream.TaskResponse); ok {
return resAsV, true // if v, ok := asyncmap.LoadAndDelete(uuid); ok {
} // if resAsV, ok := v.(pbUpstream.TaskResponse); ok {
} // return resAsV, true
// }
// }
return pbUpstream.TaskResponse{}, false // return pbUpstream.TaskResponse{}, false
} }
var recordmap sync.Map var recordmap sync.Map
var asyncmap sync.Map var asyncmap *expirable.LRU[string, pbUpstream.TaskResponse]
func init() {
asyncmap = expirable.NewLRU[string, pbUpstream.TaskResponse](10000, nil, time.Hour*1)
}
func recordUUID() { func recordUUID() {
for message := range ApiQueryTxsByAddrForQueue { for message := range ApiQueryTxsByAddrForQueue {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment