-
Notifications
You must be signed in to change notification settings - Fork 1
/
indexes.go
80 lines (74 loc) · 2.21 KB
/
indexes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package db
import (
"context"
"fmt"
"github.com/rumorsflow/rumors/v2/pkg/repository"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func SiteIndexes(indexView mongo.IndexView) error {
if _, err := indexView.CreateMany(context.Background(), []mongo.IndexModel{
{Keys: bson.D{{"domain", 1}}, Options: options.Index().SetUnique(true)},
{Keys: bson.D{
{"languages", 1},
{"title", 1},
{"enabled", 1},
}},
}); err != nil {
return fmt.Errorf("%s %w", repository.OpIndexes, err)
}
return nil
}
func ArticleIndexes(indexView mongo.IndexView) error {
if _, err := indexView.CreateMany(context.Background(), []mongo.IndexModel{
{Keys: bson.D{{"link", 1}}, Options: options.Index().SetUnique(true)},
{Keys: bson.D{{"pub_date", 1}}},
{Keys: bson.D{{"created_at", 1}}},
{Keys: bson.D{{"updated_at", 1}}},
{Keys: bson.D{{"site_id", 1}, {"lang", 1}}},
{Keys: bson.D{{"source", 1}, {"lang", 1}}},
}); err != nil {
return fmt.Errorf("%s %w", repository.OpIndexes, err)
}
return nil
}
func ChatIndexes(indexView mongo.IndexView) error {
if _, err := indexView.CreateMany(context.Background(), []mongo.IndexModel{
{Keys: bson.D{{"telegram_id", 1}}, Options: options.Index().SetUnique(true)},
{Keys: bson.D{
{"broadcast", 1},
{"blocked", 1},
{"deleted", 1},
{"created_at", 1},
{"updated_at", 1},
}},
}); err != nil {
return fmt.Errorf("%s %w", repository.OpIndexes, err)
}
return nil
}
func JobIndexes(indexView mongo.IndexView) error {
if _, err := indexView.CreateOne(context.Background(), mongo.IndexModel{Keys: bson.D{
{"name", 1},
{"enabled", 1},
{"created_at", 1},
{"updated_at", 1},
}}); err != nil {
return fmt.Errorf("%s %w", repository.OpIndexes, err)
}
return nil
}
func SysUserIndexes(indexView mongo.IndexView) error {
if _, err := indexView.CreateMany(context.Background(), []mongo.IndexModel{
{Keys: bson.D{{"username", 1}}, Options: options.Index().SetUnique(true)},
{Keys: bson.D{{"email", 1}}, Options: options.Index().SetUnique(true)},
{Keys: bson.D{
{"created_at", 1},
{"updated_at", 1},
}},
}); err != nil {
return fmt.Errorf("%s %w", repository.OpIndexes, err)
}
return nil
}