mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-14 07:19:02 +00:00
Don't give rate limit delay when project is not found
This commit is contained in:
@@ -11,7 +11,7 @@ func (api *WebAPI) ReserveSubmit(pid int64) *rate.Reservation {
|
||||
if !ok {
|
||||
project := api.Database.GetProject(pid)
|
||||
if project == nil {
|
||||
return &rate.Reservation{}
|
||||
return nil
|
||||
}
|
||||
|
||||
limiter = rate.NewLimiter(project.SubmitRate, 1)
|
||||
@@ -27,7 +27,7 @@ func (api *WebAPI) ReserveAssign(pid int64) *rate.Reservation {
|
||||
if !ok {
|
||||
project := api.Database.GetProject(pid)
|
||||
if project == nil {
|
||||
return &rate.Reservation{}
|
||||
return nil
|
||||
}
|
||||
|
||||
limiter = rate.NewLimiter(project.AssignRate, 1)
|
||||
|
||||
14
api/task.go
14
api/task.go
@@ -56,6 +56,13 @@ func (api *WebAPI) SubmitTask(r *Request) {
|
||||
}
|
||||
|
||||
reservation := api.ReserveSubmit(createReq.Project)
|
||||
if reservation == nil {
|
||||
r.Json(JsonResponse{
|
||||
Ok: false,
|
||||
Message: "Project not found",
|
||||
}, 404)
|
||||
return
|
||||
}
|
||||
delay := reservation.DelayFrom(time.Now()).Seconds()
|
||||
if delay > 0 {
|
||||
r.Json(JsonResponse{
|
||||
@@ -108,6 +115,13 @@ func (api *WebAPI) GetTaskFromProject(r *Request) {
|
||||
}
|
||||
|
||||
reservation := api.ReserveAssign(project)
|
||||
if reservation == nil {
|
||||
r.Json(JsonResponse{
|
||||
Ok: false,
|
||||
Message: "Project not found",
|
||||
}, 404)
|
||||
return
|
||||
}
|
||||
delay := reservation.DelayFrom(time.Now()).Seconds()
|
||||
if delay > 0 {
|
||||
r.Json(JsonResponse{
|
||||
|
||||
Reference in New Issue
Block a user