-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.go
118 lines (105 loc) · 2.85 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package mongodbstorage
import (
"fmt"
"strings"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var IndexPrefix = "mitum_"
var manifestIndexModels = []mongo.IndexModel{
{
Keys: bson.D{bson.E{Key: "height", Value: 1}},
Options: options.Index().
SetName(indexName("manifest_height")).
SetUnique(true),
},
}
var operationIndexModels = []mongo.IndexModel{
{
Keys: bson.D{bson.E{Key: "fact", Value: 1}},
Options: options.Index().
SetName(indexName("operation_fact")).
SetUnique(true),
},
{
Keys: bson.D{bson.E{Key: "height", Value: 1}},
Options: options.Index().
SetName(indexName("operation_height")),
},
}
var stateIndexModels = []mongo.IndexModel{
{
Keys: bson.D{bson.E{Key: "key", Value: 1}, bson.E{Key: "height", Value: 1}},
Options: options.Index().
SetName(indexName("state_key_and_height")).
SetUnique(true),
},
{
Keys: bson.D{bson.E{Key: "height", Value: 1}},
Options: options.Index().
SetName(indexName("state_height")),
},
}
var proposalIndexModels = []mongo.IndexModel{
{
Keys: bson.D{bson.E{Key: "hash_string", Value: 1}},
Options: options.Index().
SetName(indexName("proposal_hash")).
SetUnique(true),
},
{
Keys: bson.D{bson.E{Key: "height", Value: 1}, bson.E{Key: "round", Value: 1}, bson.E{Key: "proposer", Value: 1}},
Options: options.Index().
SetName(indexName("proposal_height_round_proposer")),
},
}
var stagedOperationIndexModels = []mongo.IndexModel{
{
Keys: bson.D{bson.E{Key: "hash", Value: 1}},
Options: options.Index().
SetName(indexName("hash")).
SetUnique(true),
},
{
Keys: bson.D{bson.E{Key: "inserted_at", Value: -1}},
Options: options.Index().
SetName(indexName("operation_inserted_at")),
},
}
var voteproofIndexModels = []mongo.IndexModel{
{
Keys: bson.D{bson.E{Key: "height", Value: 1}},
Options: options.Index().
SetName(indexName("voteproof_height")),
},
{
Keys: bson.D{bson.E{Key: "height", Value: 1}, bson.E{Key: "stage", Value: 1}},
Options: options.Index().
SetName(indexName("voteproof_height_and_stage")).
SetUnique(true),
},
}
var blockdataMapIndexModels = []mongo.IndexModel{
{
Keys: bson.D{bson.E{Key: "height", Value: 1}},
Options: options.Index().
SetName(indexName("blockdata_map_height")).
SetUnique(true),
},
}
var defaultIndexes = map[string] /* collection */ []mongo.IndexModel{
ColNameManifest: manifestIndexModels,
// ColNameOperation: operationIndexModels,
// ColNameProposal: proposalIndexModels,
// ColNameStagedOperation: stagedOperationIndexModels,
// ColNameState: stateIndexModels,
// ColNameVoteproof: voteproofIndexModels,
ColNameBlockdataMap: blockdataMapIndexModels,
}
func indexName(s string) string {
return fmt.Sprintf("%s%s", IndexPrefix, s)
}
func isIndexName(s, prefix string) bool {
return strings.HasPrefix(s, prefix)
}