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 2020/12/11 02:21:54 UTC

[GitHub] [servicecomb-service-center] robotLJW commented on a change in pull request #782: [SCB-2094] Supplemenet UT of instance and problem fix

robotLJW commented on a change in pull request #782:
URL: https://github.com/apache/servicecomb-service-center/pull/782#discussion_r540641351



##########
File path: datasource/mongo/ms.go
##########
@@ -2250,3 +2298,363 @@ func preProcessRegisterInstance(ctx context.Context, instance *pb.MicroServiceIn
 	instance.Version = microservice.ServiceInfo.Version
 	return nil
 }
+
+func findServices(ctx context.Context, key *pb.MicroServiceKey) ([]*Service, error) {
+	tenant := strings.Split(key.Tenant, "/")
+	rangeIdx := strings.Index(key.Version, "-")
+	switch {
+	case key.Version == "latest":
+		filter := bson.M{
+			ColumnDomain:  tenant[0],
+			ColumnProject: tenant[1],
+			StringBuilder([]string{ColumnServiceInfo, ColumnEnv}):         key.Environment,
+			StringBuilder([]string{ColumnServiceInfo, ColumnAppID}):       key.AppId,
+			StringBuilder([]string{ColumnServiceInfo, ColumnServiceName}): key.ServiceName,
+		}
+		return filterLatestServices(ctx, filter)
+	case key.Version[len(key.Version)-1:] == "+":
+		start := key.Version[:len(key.Version)-1]
+		filter := bson.M{
+			ColumnDomain:  tenant[0],
+			ColumnProject: tenant[1],
+			StringBuilder([]string{ColumnServiceInfo, ColumnEnv}):         key.Environment,
+			StringBuilder([]string{ColumnServiceInfo, ColumnAppID}):       key.AppId,
+			StringBuilder([]string{ColumnServiceInfo, ColumnServiceName}): key.ServiceName,
+			StringBuilder([]string{ColumnServiceInfo, ColumnVersion}):     bson.M{"$gt": start}}
+		return filterServices(ctx, filter)
+	case rangeIdx > 0:
+		start := key.Version[:rangeIdx]
+		end := key.Version[rangeIdx+1:]
+		filter := bson.M{
+			ColumnDomain:  tenant[0],
+			ColumnProject: tenant[1],
+			StringBuilder([]string{ColumnServiceInfo, ColumnEnv}):         key.Environment,
+			StringBuilder([]string{ColumnServiceInfo, ColumnAppID}):       key.AppId,
+			StringBuilder([]string{ColumnServiceInfo, ColumnServiceName}): key.ServiceName,
+			StringBuilder([]string{ColumnServiceInfo, ColumnVersion}):     bson.M{"$gte": start, "$lte": end}}

Review comment:
       这个没问题gte表示 >= ,lte表示 <=




----------------------------------------------------------------
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