Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion module/cold_start_recall_featurestore_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ func (d *ColdStartRecallFeatureStoreDao) ListItemsByUser(user *User, context *co
}
if cacheValue, ok := d.cache.GetIfPresent(cacheKey); ok {
if items, ok := cacheValue.([]*Item); ok {
return items
clonedItems := make([]*Item, len(items))
for i, item := range items {
clonedItems[i] = item.DeepClone()
}
return clonedItems
}
}

Expand Down
31 changes: 30 additions & 1 deletion module/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,23 @@ func (t *Item) DeepClone() *Item {
algoScores := maps.Clone(t.algoScores)
recallScores := maps.Clone(t.RecallScores)

item := NewItemWithProperty(string(t.Id), t.Properties)
// Deep copy properties to avoid sharing nested objects
clonedProperties := make(map[string]interface{}, len(t.Properties))
for k, v := range t.Properties {
clonedProperties[k] = deepCopyInterface(v)
}

item := NewItemWithProperty(string(t.Id), clonedProperties)

item.Score = t.Score
item.RetrieveId = t.RetrieveId
item.ItemType = t.ItemType

item.algoScores = algoScores
item.RecallScores = recallScores
if item.algoScores == nil {
item.algoScores = make(map[string]float64)
}
return item
}
func (t *Item) String() string {
Expand All @@ -315,3 +324,23 @@ func (t *Item) String() string {
t.Id, t.Score, t.RetrieveId, t.Properties, t.algoScores, t.RecallScores)

}

// deepCopyInterface performs deep copy of interface{} value
func deepCopyInterface(v interface{}) interface{} {
switch val := v.(type) {
case map[string]interface{}:
clonedMap := make(map[string]interface{}, len(val))
for k, v := range val {
clonedMap[k] = deepCopyInterface(v)
}
return clonedMap
case []interface{}:
clonedSlice := make([]interface{}, len(val))
for i, v := range val {
clonedSlice[i] = deepCopyInterface(v)
}
return clonedSlice
default:
return v // For primitive types, just return as-is
}
}
2 changes: 1 addition & 1 deletion module/item_state_filter_tablestore_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (d *ItemStateFilterTablestoreDao) Filter(user *User, items []*Item, ctx *co
result, err := d.filterParam.EvaluateByDomain(userFeatures, properties)
if err != nil {
log.Error(fmt.Sprintf("requestId=%smodule=ItemStateFilterTablestoreDao\tevent=EvaluateFilterParam\terror=%v", ctx.RecommendId, err))
} else if err == nil && result {
} else if result {
fieldMap[id] = true
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions module/vector_hologres_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

"github.com/alibaba/pairec/v2/log"

"github.com/huandu/go-sqlbuilder"
"github.com/alibaba/pairec/v2/persist/holo"
"github.com/alibaba/pairec/v2/recconf"
"github.com/huandu/go-sqlbuilder"
)

type VectorHologresDao struct {
Expand Down Expand Up @@ -138,7 +138,7 @@ func FetchPartition(hologresName, table, field string) string {
}
var partition string

for rows.Next() {
if rows.Next() {
if err := rows.Scan(&partition); err != nil {
log.Error(fmt.Sprintf("module=VectorHologresDao\tevent=FetchPartition\terror=%v", err))
return ""
Expand Down