another style pass
This commit is contained in:
@@ -1115,9 +1115,9 @@ func AmListConferences(ctx context.Context, cid int32, showHidden bool) ([]*Conf
|
||||
}
|
||||
rc := make([]*ConferenceSummary, 0)
|
||||
for rs.Next() {
|
||||
var cs ConferenceSummary
|
||||
cs := new(ConferenceSummary)
|
||||
if err = rs.Scan(&(cs.ConfId), &(cs.Name), &(cs.LastUpdate), &(cs.Description), &(cs.Sequence), &(cs.Hidden)); err == nil {
|
||||
rc = append(rc, &cs)
|
||||
rc = append(rc, cs)
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+10
-14
@@ -67,7 +67,7 @@ type sweepentry struct {
|
||||
|
||||
// banSweeper is a goroutine that sweeps the banned IP address cache, looking for entries that have expired
|
||||
// and kicking them out so the database can be rechecked.
|
||||
func banSweeper(done chan bool, ended chan bool, resetMe chan bool, input chan *sweepentry) {
|
||||
func banSweeper(ctx context.Context, done chan bool, resetMe chan bool, input chan *sweepentry) {
|
||||
expireTab := make([]*sweepentry, 0) // table of expiring entries
|
||||
running := true
|
||||
var topEntry *sweepentry = nil // always points to the top of expireTab
|
||||
@@ -76,7 +76,7 @@ func banSweeper(done chan bool, ended chan bool, resetMe chan bool, input chan *
|
||||
if checkTimer == nil {
|
||||
// "timer idle" mode
|
||||
select {
|
||||
case <-done:
|
||||
case <-ctx.Done():
|
||||
running = false
|
||||
case <-resetMe:
|
||||
// this is bupkis, because we're resetting nothing
|
||||
@@ -91,7 +91,7 @@ func banSweeper(done chan bool, ended chan bool, resetMe chan bool, input chan *
|
||||
} else {
|
||||
// "timer active" mode
|
||||
select {
|
||||
case <-done:
|
||||
case <-ctx.Done():
|
||||
running = false
|
||||
case <-resetMe:
|
||||
// clear out everything on a reset signal
|
||||
@@ -129,7 +129,7 @@ func banSweeper(done chan bool, ended chan bool, resetMe chan bool, input chan *
|
||||
}
|
||||
}
|
||||
}
|
||||
ended <- true // signal that we're done
|
||||
done <- true // signal that we're done
|
||||
}
|
||||
|
||||
// banSweeperReset tells the ban sweeper to clear itself.
|
||||
@@ -140,14 +140,14 @@ var banSweeperInput chan *sweepentry
|
||||
|
||||
// setupIPBanSweep sets up the IP ban sweeper routine, and returns a function that tears it down.
|
||||
func setupIPBanSweep() func() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
banSweeperReset = make(chan bool)
|
||||
banSweeperInput = make(chan *sweepentry, config.GlobalConfig.Tuning.Queues.IPBans)
|
||||
done := make(chan bool)
|
||||
ended := make(chan bool)
|
||||
go banSweeper(done, ended, banSweeperReset, banSweeperInput)
|
||||
go banSweeper(ctx, done, banSweeperReset, banSweeperInput)
|
||||
return func() {
|
||||
done <- true
|
||||
<-ended
|
||||
cancel()
|
||||
<-done
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,14 +157,10 @@ func nukeIPBanCache(bad, good bool) {
|
||||
defer banMutex.Unlock()
|
||||
if bad {
|
||||
banSweeperReset <- true // send the reset signal to the sweeper
|
||||
for k := range knownBans {
|
||||
delete(knownBans, k)
|
||||
}
|
||||
clear(knownBans)
|
||||
}
|
||||
if good {
|
||||
for k := range knownGood {
|
||||
delete(knownGood, k)
|
||||
}
|
||||
clear(knownGood)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -199,9 +199,9 @@ type TopicBozo struct {
|
||||
}
|
||||
|
||||
// GetBozos returns all filtered users for a given user on the topic.
|
||||
func (t *Topic) GetBozos(ctx context.Context, u *User) ([]TopicBozo, error) {
|
||||
func (t *Topic) GetBozos(ctx context.Context, u *User) ([]*TopicBozo, error) {
|
||||
if u.IsAnon {
|
||||
return make([]TopicBozo, 0), nil
|
||||
return make([]*TopicBozo, 0), nil
|
||||
}
|
||||
rs, err := amdb.QueryContext(ctx, `SELECT b.bozo_uid, u.username, c.given_name, c.family_name
|
||||
FROM topicbozo b, users u, contacts c WHERE b.topicid = ? AND b.uid = ? AND b.bozo_uid = u.uid AND u.contactid = c.contactid
|
||||
@@ -209,9 +209,9 @@ func (t *Topic) GetBozos(ctx context.Context, u *User) ([]TopicBozo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rc := make([]TopicBozo, 0)
|
||||
rc := make([]*TopicBozo, 0)
|
||||
for rs.Next() {
|
||||
var tb TopicBozo
|
||||
tb := new(TopicBozo)
|
||||
err = rs.Scan(&(tb.Uid), &(tb.Username), &(tb.GivenName), &(tb.FamilyName))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -279,7 +279,7 @@ func (t *Topic) GetSubscribers(ctx context.Context) ([]int32, error) {
|
||||
* List of ActivityReport objects detailing the topic activity.
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func (t *Topic) GetActivity(ctx context.Context, reportType int) ([]ActivityReport, error) {
|
||||
func (t *Topic) GetActivity(ctx context.Context, reportType int) ([]*ActivityReport, error) {
|
||||
var myfield string
|
||||
switch reportType {
|
||||
case ActivityReportPosters:
|
||||
@@ -295,9 +295,9 @@ func (t *Topic) GetActivity(ctx context.Context, reportType int) ([]ActivityRepo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rc := make([]ActivityReport, 0)
|
||||
rc := make([]*ActivityReport, 0)
|
||||
for rs.Next() {
|
||||
var cur ActivityReport
|
||||
cur := new(ActivityReport)
|
||||
err = rs.Scan(&(cur.Uid), &(cur.Username), &(cur.LastRead), &(cur.LastPost))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -698,12 +698,12 @@ func AmListTopics(ctx context.Context, confid int32, uid int32, viewOption int,
|
||||
}
|
||||
rc := make([]*TopicSummary, 0)
|
||||
for rs.Next() {
|
||||
var rec TopicSummary
|
||||
rec := new(TopicSummary)
|
||||
if err = rs.Scan(&rec.TopicID, &rec.Number, &rec.Name, &rec.Unread, &rec.Total, &rec.LastUpdate, &rec.Frozen,
|
||||
&rec.Archived, &rec.Subscribed, &rec.Hidden, &rec.Sticky, &rec.NewFlag); err != nil {
|
||||
log.Errorf("AmListTopics scan error: %v", err)
|
||||
} else {
|
||||
rc = append(rc, &rec)
|
||||
rc = append(rc, rec)
|
||||
}
|
||||
}
|
||||
return rc, nil
|
||||
|
||||
Reference in New Issue
Block a user