1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-18 07:36:24 -07:00

Fix a bunch of large value copies as suggested by deepsource

This commit is contained in:
Eggbertx 2022-05-12 11:28:15 -07:00
parent 1f3f78d1c0
commit 5bfbeabf13
9 changed files with 24 additions and 24 deletions

View file

@ -52,7 +52,7 @@ type MigrationOptions struct {
// database compatible with gochan 3.x onward
type DBMigrator interface {
// Init sets the variables for connecting to the databases
Init(options MigrationOptions) error
Init(options *MigrationOptions) error
// IsMigrated checks to see if the database has already been migrated and quits if it has
// and returns any errors that aren't "table doesn't exist". if the boolean value is true,

View file

@ -11,10 +11,10 @@ var (
type KusabaXMigrator struct {
db *gcsql.GCDB
options common.MigrationOptions
options *common.MigrationOptions
}
func (m *KusabaXMigrator) Init(options common.MigrationOptions) error {
func (m *KusabaXMigrator) Init(options *common.MigrationOptions) error {
m.options = options
return unimplemented
}

View file

@ -72,11 +72,11 @@ func (m *Pre2021Migrator) MigrateBoards() error {
return err
}
found := false
for _, board := range boards {
for b := range boards {
if _, ok := m.oldBoards[id]; !ok {
m.oldBoards[id] = dir
}
if board.Dir == dir {
if boards[b].Dir == dir {
gclog.Printf(gclog.LStdLog, "Board /%s/ already exists in new db, moving on\n", dir)
found = true
break

View file

@ -21,7 +21,7 @@ type Pre2021Config struct {
type Pre2021Migrator struct {
db *gcsql.GCDB
options common.MigrationOptions
options *common.MigrationOptions
config Pre2021Config
posts []postTable
@ -37,7 +37,7 @@ func (m *Pre2021Migrator) readConfig() error {
return json.Unmarshal(ba, &m.config)
}
func (m *Pre2021Migrator) Init(options common.MigrationOptions) error {
func (m *Pre2021Migrator) Init(options *common.MigrationOptions) error {
m.options = options
var err error
if err = m.readConfig(); err != nil {

View file

@ -11,10 +11,10 @@ var (
type TinyBoardMigrator struct {
db *gcsql.GCDB
options common.MigrationOptions
options *common.MigrationOptions
}
func (m *TinyBoardMigrator) Init(options common.MigrationOptions) error {
func (m *TinyBoardMigrator) Init(options *common.MigrationOptions) error {
m.options = options
return unimplemented
}

View file

@ -85,7 +85,7 @@ func main() {
gcsql.CheckAndInitializeDatabase(systemCritical.DBtype)
defer gcsql.Close()
err := migrator.Init(options)
err := migrator.Init(&options)
if err != nil {
gclog.Printf(fatalLogFlags,
"Unable to initialize %s migrator: %s\n", options.ChanType, err.Error())

View file

@ -50,7 +50,8 @@ func BuildBoardPages(board *gcsql.Board) error {
}
// For each top level post, start building a Thread struct
for _, op := range opPosts {
for p := range opPosts {
op := &opPosts[p]
var thread gcsql.Thread
var postsInThread []gcsql.Post
@ -70,7 +71,7 @@ func BuildBoardPages(board *gcsql.Board) error {
}
thread.NumImages = fileCount
thread.OP = op
thread.OP = *op
var numRepliesOnBoardPage int
// postCfg := config.getpo
@ -103,7 +104,8 @@ func BuildBoardPages(board *gcsql.Board) error {
// Count number of images on board page
imageCount := 0
for _, reply := range postsInThread {
for p := range postsInThread {
reply := &postsInThread[p]
if reply.Filesize != 0 {
imageCount++
}
@ -240,8 +242,9 @@ func BuildBoards(verbose bool, which ...int) error {
return nil
}
for _, board := range boards {
if err = buildBoard(&board, false, true); err != nil {
for b := range boards {
board := &boards[b]
if err = buildBoard(board, false, true); err != nil {
return errors.New(gclog.Printf(gclog.LErrorLog,
"Error building /%s/: %s", board.Dir, err.Error()))
}
@ -282,18 +285,13 @@ func BuildCatalog(boardID int) string {
"Error building catalog for /%s/: %s", board.Dir, err.Error()) + "<br />"
}
var threadInterfaces []interface{}
for _, thread := range threadOPs {
threadInterfaces = append(threadInterfaces, thread)
}
if err = serverutil.MinifyTemplate(gctemplates.Catalog, map[string]interface{}{
"boards": gcsql.AllBoards,
"webroot": criticalCfg.WebRoot,
"board": board,
"board_config": config.GetBoardConfig(board.Dir),
"sections": gcsql.AllSections,
"threads": threadInterfaces,
"threads": threadOPs,
}, catalogFile, "text/html"); err != nil {
return gclog.Printf(gclog.LErrorLog,
"Error building catalog for /%s/: %s", board.Dir, err.Error()) + "<br />"

View file

@ -31,8 +31,9 @@ func BuildThreads(all bool, boardid, threadid int) error {
return err
}
for _, op := range threads {
if err = BuildThreadPages(&op); err != nil {
for t := range threads {
op := &threads[t]
if err = BuildThreadPages(op); err != nil {
return err
}
}

View file

@ -17,7 +17,8 @@ func tempCleaner() {
for {
select {
case <-tempCleanerTicker.C:
for p, post := range gcsql.TempPosts {
for p := range gcsql.TempPosts {
post := &gcsql.TempPosts[p]
if !time.Now().After(post.Timestamp.Add(time.Minute * 5)) {
continue
}