From 354154ce1b6923fc1392084fb92c1626a15498c2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 16 Jun 2024 14:47:22 +0800 Subject: [PATCH] 1 --- server/marketserver/cache/cachemgr.go | 20 ++++++++++++++++++-- server/marketserver/common/types.go | 7 ++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/server/marketserver/cache/cachemgr.go b/server/marketserver/cache/cachemgr.go index fed77917..0d4ee7be 100644 --- a/server/marketserver/cache/cachemgr.go +++ b/server/marketserver/cache/cachemgr.go @@ -4,7 +4,6 @@ import ( "q5" "f5" "mt" - "fmt" "main/common" ) @@ -21,13 +20,30 @@ func (this *cacheMgr) UnInit() { } func (this *cacheMgr) GetNfts(nfts []*common.NftDto) { + { + nfts = []*common.NftDto{} + for _, val := range nfts { + this.fastGetNft(val) + if val.NftCache != nil { + + } + } + } + for _, val := range nfts { this.internalGetNft(val) } } +func (this *cacheMgr) fastGetNft(dto *common.NftDto) { + key := dto.GetKey() + if p, ok := this.nftHash.Load(key); ok { + dto.NftCache = *p + } +} + func (this *cacheMgr) internalGetNft(dto *common.NftDto) { - key := fmt.Sprintf("%d_%s_%s", dto.NetId, dto.ContractAddress, dto.TokenId) + key := dto.GetKey() if p, ok := this.nftHash.Load(key); ok { dto.NftCache = *p } else { diff --git a/server/marketserver/common/types.go b/server/marketserver/common/types.go index 287d071e..1d3dbe05 100644 --- a/server/marketserver/common/types.go +++ b/server/marketserver/common/types.go @@ -3,6 +3,7 @@ package common import ( "q5" "f5" + "fmt" ) type NftHomeMeta struct { @@ -86,7 +87,6 @@ type CacheMgr interface{ GetNfts([]*NftDto) } - func (this* StreamPagination) FillPage(page *f5.StreamPagination) { if page.NextCursor != 0 { this.NextCursor = q5.ToString(page.NextCursor) @@ -96,3 +96,8 @@ func (this* StreamPagination) FillPage(page *f5.StreamPagination) { } this.Remaining = page.Remaining } + +func (this* NftDto) GetKey() string { + key := fmt.Sprintf("%d_%s_%s", this.NetId, this.ContractAddress, this.TokenId) + return key +}