diff --git a/internal/assets/migrations/004_daily_questions_tabel.sql b/internal/assets/migrations/004_daily_questions.sql similarity index 93% rename from internal/assets/migrations/004_daily_questions_tabel.sql rename to internal/assets/migrations/004_daily_questions.sql index 5bc5037..74631e6 100644 --- a/internal/assets/migrations/004_daily_questions_tabel.sql +++ b/internal/assets/migrations/004_daily_questions.sql @@ -10,7 +10,6 @@ CREATE TABLE IF NOT EXISTS daily_questions ( correct_answer INTEGER NOT NULL, num_correct_answers INTEGER DEFAULT 0, num_incorrect_answers INTEGER DEFAULT 0, - num_no_answer INTEGER DEFAULT 0, num_all_participants INTEGER DEFAULT 0 ); diff --git a/internal/config/daily_questions.go b/internal/config/daily_questions.go index 10e4ff2..28029c2 100644 --- a/internal/config/daily_questions.go +++ b/internal/config/daily_questions.go @@ -59,7 +59,7 @@ func (q *DailyQuestions) GetDeadline(key string) *int64 { return &value } -func (q *DailyQuestions) SetDeadlineTimer(log *logan.Entry, question data.DailyQuestionsQ, eve *data.Event, nullifier string, deadline int64) { +func (q *DailyQuestions) SetDeadlineTimer(log *logan.Entry, question data.DailyQuestionsQ, nullifier string, deadline int64) { now := time.Now().UTC() q.muDeadlines.Lock() @@ -67,14 +67,7 @@ func (q *DailyQuestions) SetDeadlineTimer(log *logan.Entry, question data.DailyQ q.muDeadlines.Unlock() time.AfterFunc(time.Duration(deadline-now.Unix())*time.Second, func() { - q.muDeadlines.Lock() - defer q.muDeadlines.Unlock() - - if deadline <= time.Now().UTC().Unix() { - if eve != nil { - delete(q.Deadlines, nullifier) - } - } + delete(q.Deadlines, nullifier) }) err := question.IncrementAllParticipants() diff --git a/internal/data/daily_questions.go b/internal/data/daily_questions.go index 55154ce..9d82b40 100644 --- a/internal/data/daily_questions.go +++ b/internal/data/daily_questions.go @@ -15,7 +15,6 @@ type DailyQuestion struct { CorrectAnswer int64 `db:"correct_answer"` NumCorrectAnswers int64 `db:"num_correct_answers"` NumIncorrectAnswers int64 `db:"num_incorrect_answers"` - NumNoAnswer int64 `db:"num_no_answer"` NumAllParticipants int64 `db:"num_all_participants"` } diff --git a/internal/data/pg/daily_questions.go b/internal/data/pg/daily_questions.go index 2f59fc6..fd2f56b 100644 --- a/internal/data/pg/daily_questions.go +++ b/internal/data/pg/daily_questions.go @@ -43,7 +43,6 @@ func (q *dailyQuestionsQ) Insert(quest data.DailyQuestion) error { "correct_answer": quest.CorrectAnswer, "num_correct_answers": quest.NumCorrectAnswers, "num_incorrect_answers": quest.NumIncorrectAnswers, - "num_no_answer": quest.NumNoAnswer, "num_all_participants": quest.NumAllParticipants, }) @@ -127,7 +126,6 @@ func (q *dailyQuestionsQ) IncrementCorrectAnswer() error { func (q *dailyQuestionsQ) IncrementIncorrectAnswer() error { stmt := q.updater. Set("num_incorrect_answers", squirrel.Expr("num_incorrect_answers + 1")) - if err := q.db.Exec(stmt); err != nil { return fmt.Errorf("increment incorrect answer: %w", err) } @@ -136,9 +134,7 @@ func (q *dailyQuestionsQ) IncrementIncorrectAnswer() error { func (q *dailyQuestionsQ) IncrementAllParticipants() error { stmt := q.updater. - Set("num_all_participants", squirrel.Expr("num_all_participants + 1")). - Set("num_no_answer", squirrel.Expr("num_all_participants + 1 - num_correct_answers - num_incorrect_answers")) - + Set("num_all_participants", squirrel.Expr("num_all_participants + 1")) if err := q.db.Exec(stmt); err != nil { return fmt.Errorf("increment no answer: %w", err) } diff --git a/internal/service/handlers/daily_question_check.go b/internal/service/handlers/daily_question_check.go index cef95cd..f423d64 100644 --- a/internal/service/handlers/daily_question_check.go +++ b/internal/service/handlers/daily_question_check.go @@ -67,7 +67,7 @@ func CheckDailyQuestion(w http.ResponseWriter, r *http.Request) { deadline := cfg.GetDeadline(nullifier) if deadline == nil { - Log(r).Errorf("The user's nullifier was not found in active requests, it does not exist, or the user has already answered: %s", nullifier) + Log(r).Errorf("The user's nullifier was not found in inactive requests, it does not exist, or the user has already answered: %s", nullifier) ape.RenderErr(w, problems.Forbidden()) return } @@ -102,7 +102,7 @@ func CheckDailyQuestion(w http.ResponseWriter, r *http.Request) { Log(r).Infof("Wrong answer for daily question: %v", req.Answer) err = DailyQuestionsQ(r).FilterTodayQuestions(cfg.Timezone).IncrementIncorrectAnswer() if err != nil { - Log(r).WithError(err).Errorf("Error incrementing question answers incorrect answered") + Log(r).WithError(err).Errorf("Error incrementing question answers incorect answered") } return nil } diff --git a/internal/service/handlers/daily_question_get.go b/internal/service/handlers/daily_question_get.go index 860568b..e2df2d8 100644 --- a/internal/service/handlers/daily_question_get.go +++ b/internal/service/handlers/daily_question_get.go @@ -76,7 +76,7 @@ func GetDailyQuestion(w http.ResponseWriter, r *http.Request) { } nowTime := time.Now().UTC() - cfg.SetDeadlineTimer(Log(r), DailyQuestionsQ(r), questionEvent, balance.Nullifier, nowTime.Unix()+question.TimeForAnswer) + cfg.SetDeadlineTimer(Log(r), DailyQuestionsQ(r), balance.Nullifier, nowTime.Unix()+question.TimeForAnswer) options, err := ConvertJsonbToDailyQuestionOptions(question.AnswerOptions) if err != nil {