Skip to content

Commit

Permalink
apache#79 消息轨迹推送跟踪
Browse files Browse the repository at this point in the history
1.补充返回状态判断;
2.新增索引domain+sessionid+revision
  • Loading branch information
develpoerX committed Dec 28, 2020
1 parent ade7875 commit 591fdf4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions deployments/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
4 changes: 4 additions & 0 deletions server/handler/track_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions server/service/mongo/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion server/service/mongo/track/polling_detail_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 591fdf4

Please sign in to comment.