Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
package mediamod
import (
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type moduleLatestContentAt struct {
ModuleID primitive.ObjectID `bson:"_id"`
LatestCreatedAt time.Time `bson:"latestCreatedAt"`
LatestContentUpdated time.Time `bson:"latestContentUpdated"`
}
// LatestContentAtByModules 返回动漫、漫画等媒体亚模块最近一次新增或子集更新时间。
func LatestContentAtByModules(moduleIDs []primitive.ObjectID) (map[string]time.Time, error) {
result := make(map[string]time.Time, len(moduleIDs))
if len(moduleIDs) == 0 {
return result, nil
}
pipeline := []bson.M{
{"$match": bson.M{
"status": 1,
"isDelete": false,
"mId": bson.M{"$in": moduleIDs},
}},
{"$group": bson.M{
"_id": "$mId",
"latestCreatedAt": bson.M{"$max": "$createdAt"},
"latestContentUpdated": bson.M{"$max": "$contentUpdateTime"},
}},
}
var rows []moduleLatestContentAt
if err := coll(nil).Aggregate(&rows, pipeline); err != nil {
return nil, err
}
for _, row := range rows {
latest := row.LatestCreatedAt
if row.LatestContentUpdated.After(latest) {
latest = row.LatestContentUpdated
}
if !row.ModuleID.IsZero() && !latest.IsZero() {
result[row.ModuleID.Hex()] = latest
}
}
return result, nil
}