Skip to content

Commit

Permalink
remove unused LastActivityAt handling (mattermost#729)
Browse files Browse the repository at this point in the history
* remove unused LastActivityAt handling

Fixes: https://mattermost.atlassian.net/browse/MM-60177

* rm wg.Add(1)
  • Loading branch information
lieut-data authored Aug 26, 2024
1 parent bcc84f7 commit b09957f
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 148 deletions.
28 changes: 0 additions & 28 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"regexp"
"strings"
"sync"
"time"

"github.com/enescakir/emoji"
"github.com/mattermost/mattermost-plugin-msteams/server/metrics"
Expand All @@ -31,7 +30,6 @@ type ActivityHandler struct {
quit chan bool
workersWaitGroup sync.WaitGroup
IgnorePluginHooksMap sync.Map
lastUpdateAtMap sync.Map
}

func NewActivityHandler(plugin *Plugin) *ActivityHandler {
Expand Down Expand Up @@ -80,30 +78,6 @@ func (ah *ActivityHandler) Start() {
ah.workersWaitGroup.Done()
}

// doStart is the meat of the activity handler worker
doStartLastActivityAt := func() {
updateLastActivityAt := func(subscriptionID, lastUpdateAt any) bool {
if time.Since(lastUpdateAt.(time.Time)) <= 5*time.Minute {
if err := ah.plugin.GetStore().UpdateSubscriptionLastActivityAt(subscriptionID.(string), lastUpdateAt.(time.Time)); err != nil {
ah.plugin.GetAPI().LogWarn("Error storing the subscription last activity at", "error", err, "subscription_id", subscriptionID.(string), "last_update_at", lastUpdateAt.(time.Time))
}
}
return true
}
for {
timer := time.NewTimer(5 * time.Minute)
select {
case <-timer.C:
ah.lastUpdateAtMap.Range(updateLastActivityAt)
case <-ah.quit:
// we have received a signal to stop
timer.Stop()
ah.lastUpdateAtMap.Range(updateLastActivityAt)
return
}
}
}

// isQuitting informs the recovery handler if the shutdown is intentional
isQuitting := func() bool {
select {
Expand All @@ -120,8 +94,6 @@ func (ah *ActivityHandler) Start() {
ah.workersWaitGroup.Add(1)
startWorker(logError, ah.plugin.GetMetrics(), isQuitting, doStart, doQuit)
}
ah.workersWaitGroup.Add(1)
startWorker(logError, ah.plugin.GetMetrics(), isQuitting, doStartLastActivityAt, doQuit)
}

func (ah *ActivityHandler) Stop() {
Expand Down
6 changes: 3 additions & 3 deletions server/metrics/mocks/Metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 0 additions & 37 deletions server/store/mocks/Store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions server/store/sqlstore/public_methods.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions server/store/sqlstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,48 +645,6 @@ func (s *SQLStore) updateSubscriptionExpiresOn(db sq.BaseRunner, subscriptionID
return nil
}

func (s *SQLStore) updateSubscriptionLastActivityAt(db sq.BaseRunner, subscriptionID string, lastActivityAt time.Time) error {
query := s.getQueryBuilder(db).
Update(subscriptionsTableName).
Set("lastActivityAt", lastActivityAt.UnixMicro()).
Where(sq.And{
sq.Eq{"subscriptionID": subscriptionID},
sq.Or{sq.Lt{"lastActivityAt": lastActivityAt.UnixMicro()}, sq.Eq{"lastActivityAt": nil}},
})
_, err := query.Exec()
if err != nil {
return err
}
return nil
}

//db:withReplica
func (s *SQLStore) getSubscriptionsLastActivityAt(db sq.BaseRunner) (map[string]time.Time, error) {
query := s.getQueryBuilder(db).
Select("subscriptionID, lastActivityAt").
From(subscriptionsTableName).
Where(
sq.NotEq{"lastActivityAt": nil},
sq.NotEq{"lastActivityAt": 0},
)
rows, err := query.Query()
if err != nil {
return nil, err
}
defer rows.Close()

result := map[string]time.Time{}
for rows.Next() {
var lastActivityAt int64
var subscriptionID string
if scanErr := rows.Scan(&subscriptionID, &lastActivityAt); scanErr != nil {
return nil, scanErr
}
result[subscriptionID] = time.UnixMicro(lastActivityAt)
}
return result, nil
}

func (s *SQLStore) deleteSubscription(db sq.BaseRunner, subscriptionID string) error {
if _, err := s.getQueryBuilder(db).Delete(subscriptionsTableName).Where(sq.Eq{"subscriptionID": subscriptionID}).Exec(); err != nil {
return err
Expand Down
2 changes: 0 additions & 2 deletions server/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,4 @@ type Store interface {
GetChatSubscription(subscriptionID string) (*storemodels.ChatSubscription, error)
GetGlobalSubscription(subscriptionID string) (*storemodels.GlobalSubscription, error)
GetSubscriptionType(subscriptionID string) (string, error)
UpdateSubscriptionLastActivityAt(subscriptionID string, lastActivityAt time.Time) error
GetSubscriptionsLastActivityAt() (map[string]time.Time, error)
}
28 changes: 0 additions & 28 deletions server/store/timerlayer/timerlayer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b09957f

Please sign in to comment.