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)
|
rc := make([]*ConferenceSummary, 0)
|
||||||
for rs.Next() {
|
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 {
|
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 {
|
} else {
|
||||||
return nil, err
|
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
|
// 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.
|
// 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
|
expireTab := make([]*sweepentry, 0) // table of expiring entries
|
||||||
running := true
|
running := true
|
||||||
var topEntry *sweepentry = nil // always points to the top of expireTab
|
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 {
|
if checkTimer == nil {
|
||||||
// "timer idle" mode
|
// "timer idle" mode
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-ctx.Done():
|
||||||
running = false
|
running = false
|
||||||
case <-resetMe:
|
case <-resetMe:
|
||||||
// this is bupkis, because we're resetting nothing
|
// 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 {
|
} else {
|
||||||
// "timer active" mode
|
// "timer active" mode
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-ctx.Done():
|
||||||
running = false
|
running = false
|
||||||
case <-resetMe:
|
case <-resetMe:
|
||||||
// clear out everything on a reset signal
|
// 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.
|
// 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.
|
// setupIPBanSweep sets up the IP ban sweeper routine, and returns a function that tears it down.
|
||||||
func setupIPBanSweep() func() {
|
func setupIPBanSweep() func() {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
banSweeperReset = make(chan bool)
|
banSweeperReset = make(chan bool)
|
||||||
banSweeperInput = make(chan *sweepentry, config.GlobalConfig.Tuning.Queues.IPBans)
|
banSweeperInput = make(chan *sweepentry, config.GlobalConfig.Tuning.Queues.IPBans)
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
ended := make(chan bool)
|
go banSweeper(ctx, done, banSweeperReset, banSweeperInput)
|
||||||
go banSweeper(done, ended, banSweeperReset, banSweeperInput)
|
|
||||||
return func() {
|
return func() {
|
||||||
done <- true
|
cancel()
|
||||||
<-ended
|
<-done
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,14 +157,10 @@ func nukeIPBanCache(bad, good bool) {
|
|||||||
defer banMutex.Unlock()
|
defer banMutex.Unlock()
|
||||||
if bad {
|
if bad {
|
||||||
banSweeperReset <- true // send the reset signal to the sweeper
|
banSweeperReset <- true // send the reset signal to the sweeper
|
||||||
for k := range knownBans {
|
clear(knownBans)
|
||||||
delete(knownBans, k)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if good {
|
if good {
|
||||||
for k := range knownGood {
|
clear(knownGood)
|
||||||
delete(knownGood, k)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -199,9 +199,9 @@ type TopicBozo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetBozos returns all filtered users for a given user on the topic.
|
// 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 {
|
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
|
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
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rc := make([]TopicBozo, 0)
|
rc := make([]*TopicBozo, 0)
|
||||||
for rs.Next() {
|
for rs.Next() {
|
||||||
var tb TopicBozo
|
tb := new(TopicBozo)
|
||||||
err = rs.Scan(&(tb.Uid), &(tb.Username), &(tb.GivenName), &(tb.FamilyName))
|
err = rs.Scan(&(tb.Uid), &(tb.Username), &(tb.GivenName), &(tb.FamilyName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -279,7 +279,7 @@ func (t *Topic) GetSubscribers(ctx context.Context) ([]int32, error) {
|
|||||||
* List of ActivityReport objects detailing the topic activity.
|
* List of ActivityReport objects detailing the topic activity.
|
||||||
* Standard Go error status.
|
* 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
|
var myfield string
|
||||||
switch reportType {
|
switch reportType {
|
||||||
case ActivityReportPosters:
|
case ActivityReportPosters:
|
||||||
@@ -295,9 +295,9 @@ func (t *Topic) GetActivity(ctx context.Context, reportType int) ([]ActivityRepo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rc := make([]ActivityReport, 0)
|
rc := make([]*ActivityReport, 0)
|
||||||
for rs.Next() {
|
for rs.Next() {
|
||||||
var cur ActivityReport
|
cur := new(ActivityReport)
|
||||||
err = rs.Scan(&(cur.Uid), &(cur.Username), &(cur.LastRead), &(cur.LastPost))
|
err = rs.Scan(&(cur.Uid), &(cur.Username), &(cur.LastRead), &(cur.LastPost))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -698,12 +698,12 @@ func AmListTopics(ctx context.Context, confid int32, uid int32, viewOption int,
|
|||||||
}
|
}
|
||||||
rc := make([]*TopicSummary, 0)
|
rc := make([]*TopicSummary, 0)
|
||||||
for rs.Next() {
|
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,
|
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 {
|
&rec.Archived, &rec.Subscribed, &rec.Hidden, &rec.Sticky, &rec.NewFlag); err != nil {
|
||||||
log.Errorf("AmListTopics scan error: %v", err)
|
log.Errorf("AmListTopics scan error: %v", err)
|
||||||
} else {
|
} else {
|
||||||
rc = append(rc, &rec)
|
rc = append(rc, rec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rc, nil
|
return rc, nil
|
||||||
|
|||||||
+2
-6
@@ -154,13 +154,9 @@ func recycleMessages(messages chan *amMessage, done chan bool) {
|
|||||||
m.bcc = make([]string, 0)
|
m.bcc = make([]string, 0)
|
||||||
m.subject = ""
|
m.subject = ""
|
||||||
m.text = ""
|
m.text = ""
|
||||||
for k := range m.headers {
|
clear(m.headers)
|
||||||
delete(m.headers, k)
|
|
||||||
}
|
|
||||||
m.template = ""
|
m.template = ""
|
||||||
for k := range m.vars {
|
clear(m.vars)
|
||||||
delete(m.vars, k)
|
|
||||||
}
|
|
||||||
freeMessages.Put(m)
|
freeMessages.Put(m)
|
||||||
}
|
}
|
||||||
done <- true
|
done <- true
|
||||||
|
|||||||
+2
-5
@@ -90,11 +90,8 @@ func formatMessage(ctx context.Context, m *amMessage) ([]byte, error) {
|
|||||||
hdrs[fmt.Sprintf("X-Disclaimer-%d", i+1)] = v
|
hdrs[fmt.Sprintf("X-Disclaimer-%d", i+1)] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the header keys tro make for a better presentation.
|
// Sort the header keys to make for a better presentation.
|
||||||
keys := make([]string, 0, len(hdrs))
|
keys := slices.Collect(maps.Keys(hdrs))
|
||||||
for k := range hdrs {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
slices.Sort(keys)
|
slices.Sort(keys)
|
||||||
|
|
||||||
// Build the actual message.
|
// Build the actual message.
|
||||||
|
|||||||
@@ -1071,12 +1071,8 @@ func (ht *htmlCheckerImpl) Reset() {
|
|||||||
ht.outputBuffer.Reset()
|
ht.outputBuffer.Reset()
|
||||||
ht.tempBuffer.Reset()
|
ht.tempBuffer.Reset()
|
||||||
ht.tagStack.Clear()
|
ht.tagStack.Clear()
|
||||||
for u := range ht.externalReferences {
|
clear(ht.externalReferences)
|
||||||
delete(ht.externalReferences, u)
|
clear(ht.internalReferences)
|
||||||
}
|
|
||||||
for k := range ht.internalReferences {
|
|
||||||
delete(ht.internalReferences, k)
|
|
||||||
}
|
|
||||||
for _, c := range ht.counters {
|
for _, c := range ht.counters {
|
||||||
c.Reset()
|
c.Reset()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,10 +366,7 @@ func ManageSideboxes(ctxt ui.AmContext) (string, any) {
|
|||||||
ctxt.VarMap().Set("sideboxes", disp)
|
ctxt.VarMap().Set("sideboxes", disp)
|
||||||
|
|
||||||
// Create the list of available sideboxes to add.
|
// Create the list of available sideboxes to add.
|
||||||
addList := make([]*DisplaySidebox, 0, len(avail))
|
addList := slices.Collect(maps.Values(avail))
|
||||||
for _, v := range avail {
|
|
||||||
addList = append(addList, v)
|
|
||||||
}
|
|
||||||
if len(addList) > 0 {
|
if len(addList) > 0 {
|
||||||
slices.SortFunc(addList, func(a, b *DisplaySidebox) int {
|
slices.SortFunc(addList, func(a, b *DisplaySidebox) int {
|
||||||
return strings.Compare(strings.ToLower(a.Title), strings.ToLower(b.Title))
|
return strings.Compare(strings.ToLower(a.Title), strings.ToLower(b.Title))
|
||||||
|
|||||||
+1
-3
@@ -192,9 +192,7 @@ func (sess *amSession) Set(key, value any) {
|
|||||||
func (sess *amSession) Erase() {
|
func (sess *amSession) Erase() {
|
||||||
sess.mutex.Lock()
|
sess.mutex.Lock()
|
||||||
defer sess.mutex.Unlock()
|
defer sess.mutex.Unlock()
|
||||||
for k := range sess.values {
|
clear(sess.values)
|
||||||
delete(sess.values, k)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uid returns the current user ID associated with this session.
|
// Uid returns the current user ID associated with this session.
|
||||||
|
|||||||
Reference in New Issue
Block a user