another style pass

This commit is contained in:
2026-03-12 11:58:16 -06:00
parent 7e34c33e58
commit b69a5e57a2
8 changed files with 29 additions and 49 deletions
+2 -2
View File
@@ -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
View File
@@ -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
View File
@@ -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
+2 -6
View File
@@ -154,13 +154,9 @@ func recycleMessages(messages chan *amMessage, done chan bool) {
m.bcc = make([]string, 0)
m.subject = ""
m.text = ""
for k := range m.headers {
delete(m.headers, k)
}
clear(m.headers)
m.template = ""
for k := range m.vars {
delete(m.vars, k)
}
clear(m.vars)
freeMessages.Put(m)
}
done <- true
+2 -5
View File
@@ -90,11 +90,8 @@ func formatMessage(ctx context.Context, m *amMessage) ([]byte, error) {
hdrs[fmt.Sprintf("X-Disclaimer-%d", i+1)] = v
}
// Sort the header keys tro make for a better presentation.
keys := make([]string, 0, len(hdrs))
for k := range hdrs {
keys = append(keys, k)
}
// Sort the header keys to make for a better presentation.
keys := slices.Collect(maps.Keys(hdrs))
slices.Sort(keys)
// Build the actual message.
+2 -6
View File
@@ -1071,12 +1071,8 @@ func (ht *htmlCheckerImpl) Reset() {
ht.outputBuffer.Reset()
ht.tempBuffer.Reset()
ht.tagStack.Clear()
for u := range ht.externalReferences {
delete(ht.externalReferences, u)
}
for k := range ht.internalReferences {
delete(ht.internalReferences, k)
}
clear(ht.externalReferences)
clear(ht.internalReferences)
for _, c := range ht.counters {
c.Reset()
}
+1 -4
View File
@@ -366,10 +366,7 @@ func ManageSideboxes(ctxt ui.AmContext) (string, any) {
ctxt.VarMap().Set("sideboxes", disp)
// Create the list of available sideboxes to add.
addList := make([]*DisplaySidebox, 0, len(avail))
for _, v := range avail {
addList = append(addList, v)
}
addList := slices.Collect(maps.Values(avail))
if len(addList) > 0 {
slices.SortFunc(addList, func(a, b *DisplaySidebox) int {
return strings.Compare(strings.ToLower(a.Title), strings.ToLower(b.Title))
+1 -3
View File
@@ -192,9 +192,7 @@ func (sess *amSession) Set(key, value any) {
func (sess *amSession) Erase() {
sess.mutex.Lock()
defer sess.mutex.Unlock()
for k := range sess.values {
delete(sess.values, k)
}
clear(sess.values)
}
// Uid returns the current user ID associated with this session.