chore(deps): update module github.com/coreos/go-oidc to v3 - autoclosed #17

Closed
renovate-bot wants to merge 55 commits from renovate/github.com-coreos-go-oidc-3.x into master
2 changed files with 16 additions and 4 deletions
Showing only changes of commit 1e17c7bb40 - Show all commits

2
db.go
View File

@ -156,7 +156,7 @@ CREATE TABLE IF NOT EXISTS student_corrected(
return err return err
} }
if _, err := db.Exec(` if _, err := db.Exec(`
CREATE VIEW IF NOT EXISTS student_scores AS SELECT U.id_user, id_survey, Q.id_question, MAX(R.score) as score FROM survey_quests Q CROSS JOIN users U LEFT JOIN survey_responses R ON Q.id_question = R.id_question AND R.id_user = U.id_user GROUP BY Q.id_question, U.id_user; CREATE VIEW IF NOT EXISTS student_scores AS SELECT T.id_user, T.id_survey, Q.id_question, MAX(R.score) AS score FROM (SELECT DISTINCT R.id_user, S.id_survey FROM survey_responses R INNER JOIN survey_quests Q ON R.id_question = Q.id_question INNER JOIN surveys S ON Q.id_survey = S.id_survey) T LEFT OUTER JOIN survey_quests Q ON T.id_survey = Q.id_survey LEFT OUTER JOIN survey_responses R ON R.id_user = T.id_user AND Q.id_question = R.id_question GROUP BY id_user, id_survey, id_question;
`); err != nil { `); err != nil {
return err return err
} }

View File

@ -12,6 +12,10 @@ import (
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
) )
var (
_score_cache = map[int64]map[int64]*float64{}
)
func init() { func init() {
router.GET("/api/surveys", apiAuthHandler( router.GET("/api/surveys", apiAuthHandler(
func(u *User, _ httprouter.Params, _ []byte) HTTPResponse { func(u *User, _ httprouter.Params, _ []byte) HTTPResponse {
@ -182,9 +186,17 @@ func NewSurvey(title string, promo uint, group string, shown bool, startAvailabi
} }
func (s Survey) GetScore(u *User) (score *float64, err error) { func (s Survey) GetScore(u *User) (score *float64, err error) {
err = DBQueryRow("SELECT SUM(score)/COUNT(*) FROM student_scores WHERE id_survey=? AND id_user=?", s.Id, u.Id).Scan(&score) if _, ok := _score_cache[u.Id]; !ok {
if score != nil { _score_cache[u.Id] = map[int64]*float64{}
*score = *score / 5.0 }
if v, ok := _score_cache[u.Id][s.Id]; ok {
score = v
} else {
err = DBQueryRow("SELECT SUM(score)/COUNT(*) FROM student_scores WHERE id_survey=? AND id_user=?", s.Id, u.Id).Scan(&score)
if score != nil {
*score = *score / 5.0
}
_score_cache[u.Id][s.Id] = score
} }
return return
} }