You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/02/09 07:55:39 UTC

[GitHub] [servicecomb-service-center] DFSOrange commented on a change in pull request #855: add ensure index and validate

DFSOrange commented on a change in pull request #855:
URL: https://github.com/apache/servicecomb-service-center/pull/855#discussion_r572662399



##########
File path: datasource/mongo/mongo.go
##########
@@ -100,64 +97,127 @@ func (ds *DataSource) initClient() error {
 	}
 }
 
-//{Key: StringBuilder([]string{ColumnService, ColumnAlias}), Value: bsonx.Int32(1)}
-func (ds *DataSource) createIndexes() (err error) {
-	err = client.GetMongoClient().CreateIndexes(context.TODO(), CollectionService, []mongo.IndexModel{{
-		Keys:    bsonx.Doc{{Key: StringBuilder([]string{ColumnService, ColumnServiceID}), Value: bsonx.Int32(1)}},
-		Options: options.Index().SetUnique(true),
-	}, {
-		Keys: bsonx.Doc{{Key: StringBuilder([]string{ColumnService, ColumnAppID}), Value: bsonx.Int32(1)},
-			{Key: StringBuilder([]string{ColumnService, ColumnServiceName}), Value: bsonx.Int32(1)},
-			{Key: StringBuilder([]string{ColumnService, ColumnEnv}), Value: bsonx.Int32(1)},
-			{Key: StringBuilder([]string{ColumnService, ColumnVersion}), Value: bsonx.Int32(1)},
-			{Key: ColumnDomain, Value: bsonx.Int32(1)},
-			{Key: ColumnProject, Value: bsonx.Int32(1)},
-		},
-		Options: options.Index().SetUnique(true),
-	}})
+func EnsureDB() {
+	EnsureService()
+	EnsureInstance()
+	EnsureRule()
+	EnsureSchema()
+	EnsureDep()
+}
+
+func EnsureService() {
+	err := client.GetMongoClient().GetDB().CreateCollection(context.Background(), CollectionService, options.CreateCollection().SetValidator(nil))
+	wrapCreateCollectionError(err)
+
+	serviceIDIndex := BuildIndexDoc(
+		StringBuilder([]string{ColumnService, ColumnServiceID}))

Review comment:
       > 是不是没这个索引?这个索引是用来干嘛的
   
   只是单纯建立索引,加快查询单个service详情的接口 (根据serviceid-->service信息)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org