From 1d8f9871455ac4e7a124b82a24a31ed18ed961aa Mon Sep 17 00:00:00 2001 From: rtz12 Date: Tue, 15 Nov 2016 21:08:22 +0100 Subject: Alles in einem, weil wegen Race-Conditions diff --git a/modules/lists/lists.go b/modules/lists/lists.go index 05baf4a..ada4c4b 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go @@ -537,13 +537,9 @@ func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprou return } - rank := 0 - if len(list.Grils) > 0 { - rank = list.Grils[len(list.Grils)-1].Order + 1 - } - // rein in die DB damit - _, err = m.g.DB.Exec(`INSERT INTO grilist.lists_grils(list_id, gril_id, "order") VALUES($1, $2, $3)`, listID, grilID, rank) + _, err = m.g.DB.Exec(`INSERT INTO grilist.lists_grils(list_id, gril_id, "order") + VALUES($1, $2, (SELECT count(gril_id) FROM grilist.lists_grils WHERE list_id = $1));`, listID, grilID) if err != nil { log.Println("error inserting gril into list:", err) http.Error(w, "could not insert gril", 500) -- cgit v0.10.1