thread-master/apps/backend/internal/module/scout/repository/mongo_indexes.go

29 lines
1.3 KiB
Go
Raw Normal View History

2026-08-13 02:22:24 +00:00
package repository
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// RunIndexModels is consumed by cmd/init. Keeping index definitions outside
// request paths makes startup idempotent and keeps owner-scoped paging fast.
func RunIndexModels() []mongo.IndexModel {
return []mongo.IndexModel{
{Keys: bson.D{{Key: "owner_uid", Value: 1}, {Key: "created_at", Value: -1}, {Key: "_id", Value: -1}}, Options: options.Index().SetName("scout_runs_owner_created")},
{Keys: bson.D{{Key: "owner_uid", Value: 1}, {Key: "brand_id", Value: 1}, {Key: "mode", Value: 1}, {Key: "created_at", Value: -1}}, Options: options.Index().SetName("scout_runs_owner_filter")},
}
}
func RunPostIndexModels() []mongo.IndexModel {
return []mongo.IndexModel{
{Keys: bson.D{{Key: "owner_uid", Value: 1}, {Key: "run_id", Value: 1}, {Key: "score", Value: -1}, {Key: "posted_at", Value: -1}, {Key: "created_at", Value: -1}, {Key: "_id", Value: -1}}, Options: options.Index().SetName("scout_posts_run_score")},
}
}
func SeenIdentityIndexModels() []mongo.IndexModel {
return []mongo.IndexModel{
{Keys: bson.D{{Key: "owner_uid", Value: 1}, {Key: "identity", Value: 1}}, Options: options.Index().SetName("scout_seen_owner_identity")},
}
}