Skip to content

Commit

Permalink
Save experimental solutions 🎉
Browse files Browse the repository at this point in the history
Nothing is shown on /rankings yet but it's a start :-)

Updates code-golf#893
  • Loading branch information
JRaspass committed Nov 20, 2024
1 parent 5c87f4f commit 3ba27f9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion routes/hole.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func holeGET(w http.ResponseWriter, r *http.Request) {

golfer := session.Golfer(r)

if golfer != nil && data.Hole.Experiment == 0 {
if golfer != nil {
// Fetch all the code per lang.
rows, err := session.Database(r).Query(
`SELECT code, lang, scoring
Expand Down
18 changes: 18 additions & 0 deletions routes/legacy_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ func solutionPOST(w http.ResponseWriter, r *http.Request) {
out.Cheevos = append(out.Cheevos, *c)
}
}

// TODO Eventually save exp langs too.
if experimentalHole && !experimentalLang {
if _, err := db.ExecContext(
r.Context(),
`SELECT save_solution(
bytes := octet_length($1),
chars := char_length($1),
code := $1,
hole := $2,
lang := $3,
user_id := $4
)`,
in.Code, in.Hole, in.Lang, golfer.ID,
); err != nil {
panic(err)
}
}
} else if pass && golfer != nil && !experimental {
if err := db.QueryRowContext(
r.Context(),
Expand Down
6 changes: 5 additions & 1 deletion sql/c-other-functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ BEGIN
AND solutions.scoring = 'chars';
END IF;

ret.earned := earn_cheevos(hole, lang, user_id);
-- Only earn cheevos if the hole isn't experimental.
SELECT experiment = 0 INTO found FROM holes WHERE id = hole;
IF found THEN
ret.earned := earn_cheevos(hole, lang, user_id);
END IF;

RETURN ret;
END;
Expand Down

0 comments on commit 3ba27f9

Please sign in to comment.