cleanup code
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.infra.nkode.tech/dkelly/nkode-core/config"
|
||||
"git.infra.nkode.tech/dkelly/nkode-core/entities"
|
||||
"git.infra.nkode.tech/dkelly/nkode-core/security"
|
||||
"git.infra.nkode.tech/dkelly/nkode-core/sqlc"
|
||||
@@ -409,39 +408,12 @@ func (d *SqliteRepository) getSvgsById(ids []int) ([]string, error) {
|
||||
}
|
||||
|
||||
func (d *SqliteRepository) getRandomIds(count int) ([]int, error) {
|
||||
tx, err := d.Queue.Db.Begin()
|
||||
totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil, config.ErrSqliteTx
|
||||
}
|
||||
rows, err := tx.Query("SELECT COUNT(*) as count FROM svg_icon;")
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return nil, config.ErrSqliteTx
|
||||
}
|
||||
var tableLen int
|
||||
if !rows.Next() {
|
||||
return nil, config.ErrEmptySvgTable
|
||||
}
|
||||
|
||||
if err = rows.Scan(&tableLen); err != nil {
|
||||
log.Print(err)
|
||||
return nil, config.ErrSqliteTx
|
||||
}
|
||||
perm, err := security.RandomPermutation(tableLen)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for idx := range perm {
|
||||
perm[idx] += 1
|
||||
}
|
||||
|
||||
if err = tx.Commit(); err != nil {
|
||||
log.Print(err)
|
||||
return nil, config.ErrSqliteTx
|
||||
}
|
||||
perm, err := security.RandomPermutation(int(totalRows))
|
||||
|
||||
return perm[:count], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user