Fix slow-ass code
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user