Skip to content

Commit

Permalink
Update genres in chunks. Should fix #1368
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Sep 26, 2021
1 parent 482c2de commit 5680e53
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions persistence/sql_genres.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ func (r *sqlRepository) updateGenres(id string, tableName string, genres model.G
return nil
}
ins := Insert(tableName+"_genres").Columns("genre_id", tableName+"_id")
var genreIds []string
for _, g := range genres {
ins = ins.Values(g.ID, id)
genreIds = append(genreIds, g.ID)
}
_, err = r.executeSQL(ins)
err = utils.RangeByChunks(genreIds, 100, func(ids []string) error {
for _, gid := range ids {
ins = ins.Values(gid, id)
}
_, err = r.executeSQL(ins)
return err
})
return err
}

Expand Down

0 comments on commit 5680e53

Please sign in to comment.