Fix slow-ass code

This commit is contained in:
2025-01-13 20:06:55 +01:00
parent ee847020f7
commit d1225d3258
5 changed files with 41 additions and 23 deletions

View File

@ -90,12 +90,12 @@ func (app *application) CreateElection(w http.ResponseWriter, r *http.Request) {
voterIdentities := make([]string, 0, request.MaxVoters) // TODO: this is way too slow
for i := 0; i < request.MaxVoters; i++ {
randomIdentity := randomVoterIdentity()
_, err := app.voters.Insert(randomIdentity, electionId)
if err != nil {
app.serverError(w, r, err)
}
voterIdentities = append(voterIdentities, randomIdentity)
}
_, err := app.voters.InsertMultiple(voterIdentities, electionId)
if err != nil {
app.serverError(w, r, err)
}
res, err = json.Marshal(api.CreateElectionResponse{VoterIdentities: &voterIdentities})
if err != nil {
@ -248,7 +248,7 @@ func (app *application) createVotesHandleUnknownVotersElection(w http.ResponseWr
return "", fmt.Errorf(message)
}
_, err = app.voters.Insert(voterIdentity, election.ID)
_, err = app.voters.InsertMultiple([]string{voterIdentity}, election.ID)
if err != nil {
app.serverError(w, r, err)
return "", err