diff --git a/deployments/db.js b/deployments/db.js index 99f2c710..5447e975 100644 --- a/deployments/db.js +++ b/deployments/db.js @@ -120,6 +120,7 @@ db.kv_revision.createIndex({"delete_time": 1}, {expireAfterSeconds: 7 * 24 * 360 db.label.createIndex({"id": 1}, {unique: true}); db.label.createIndex({format: 1, domain: 1, project: 1}, {unique: true}); db.polling_detail.createIndex({timestamp: 1}, {expireAfterSeconds: 7 * 24 * 3600}); +db.polling_detail.createIndex({revision: 1, session_id: 1, domain: 1}, {unique: true}); db.counter.createIndex({name: 1, domain: 1}, {unique: true}); db.view.createIndex({"id": 1}, {unique: true}); db.view.createIndex({display: 1, domain: 1, project: 1}, {unique: true}); diff --git a/server/handler/track_handler.go b/server/handler/track_handler.go index 4228c984..f633478b 100644 --- a/server/handler/track_handler.go +++ b/server/handler/track_handler.go @@ -61,6 +61,10 @@ func (h *TrackHandler) Handle(chain *handler.Chain, inv *invocation.Invocation, return } chain.Next(inv, func(ir *invocation.Response) { + if ir.Status != 200 { + cb(ir) + return + } resp, _ := ir.Result.(*restful.Response) revStr := req.QueryParameter(common.QueryParamRev) wait := req.QueryParameter(common.QueryParamWait) diff --git a/server/service/mongo/session/session.go b/server/service/mongo/session/session.go index e55e16b7..4d1378b1 100644 --- a/server/service/mongo/session/session.go +++ b/server/service/mongo/session/session.go @@ -232,6 +232,11 @@ func ensureKVLongPolling(session *mgo.Session) { ExpireAfter: 7 * 24 * time.Hour, }) wrapError(err) + err = c.EnsureIndex(mgo.Index{ + Key: []string{"revision", "domain", "session_id"}, + Unique: true, + }) + wrapError(err) } func ensureView(session *mgo.Session) { diff --git a/server/service/mongo/track/polling_detail_dao.go b/server/service/mongo/track/polling_detail_dao.go index f9cc8c5b..3380ebff 100644 --- a/server/service/mongo/track/polling_detail_dao.go +++ b/server/service/mongo/track/polling_detail_dao.go @@ -32,7 +32,7 @@ import ( //If revision and session_id is exist: update else:insert func CreateOrUpdate(ctx context.Context, detail *model.PollingDetail) (*model.PollingDetail, error) { collection := session.GetDB().Collection(session.CollectionPollingDetail) - queryFilter := bson.M{"revision": detail.Domain, "session_id": detail.SessionID} + queryFilter := bson.M{"revision": detail.Revision, "domain": detail.Domain, "session_id": detail.SessionID} res := collection.FindOne(ctx, queryFilter) if res.Err() != nil { if res.Err() == mongo.ErrNoDocuments {