feat: unify owned and competitor work analysis
This commit is contained in:
+14
-11
@@ -127,8 +127,7 @@ func (s *Store) LoadWorksGrowth(ctx context.Context, workIDs []string, filter Wo
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ApplyWorkGrowthFilter 为作品列表附加增速并按条件过滤、排序(增速降序)。
|
||||
// 只有设置了 MinLikes 才改变排序;否则保持原顺序仅附加增速。
|
||||
// ApplyWorkGrowthFilter 为作品列表附加增量并按条件过滤,不改变显式选择的顺序。
|
||||
func ApplyWorkGrowthFilter(works []Work, growth map[string]WorkGrowth, filter WorkGrowthFilter) ([]Work, error) {
|
||||
filter, err := normalizeGrowthFilter(filter)
|
||||
if err != nil {
|
||||
@@ -147,16 +146,20 @@ func ApplyWorkGrowthFilter(works []Work, growth map[string]WorkGrowth, filter Wo
|
||||
}
|
||||
result = append(result, work)
|
||||
}
|
||||
if filter.MinLikes != nil {
|
||||
sort.SliceStable(result, func(i, j int) bool {
|
||||
gi, gj := result[i].LikesGrowth, result[j].LikesGrowth
|
||||
if gi == nil || gj == nil {
|
||||
return gj == nil && gi != nil
|
||||
}
|
||||
return *gi > *gj
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func sortWorksGrowth(works []Work, order string) {
|
||||
sort.SliceStable(works, func(i, j int) bool {
|
||||
left, right := works[i].LikesGrowth, works[j].LikesGrowth
|
||||
if left == nil || right == nil {
|
||||
return left != nil && right == nil
|
||||
}
|
||||
if order == "asc" {
|
||||
return *left < *right
|
||||
}
|
||||
return *left > *right
|
||||
})
|
||||
}
|
||||
|
||||
func int64Ptr(value int64) *int64 { return &value }
|
||||
|
||||
Reference in New Issue
Block a user