Skip to content

Commit

Permalink
Fix duplicate response when URL is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Jun 16, 2024
1 parent 733a555 commit 6d24496
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions service/mastodon/mastodon.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type Mastodon struct {
store *storage.Storage
pub *publish.Publish

archiving map[mastodon.ID]bool
archiving map[mastodon.ID]bool
processing map[mastodon.ID]int

clearTick *time.Ticker
fetchTick *time.Ticker
Expand Down Expand Up @@ -104,6 +105,7 @@ func (m *Mastodon) Serve() error {

go func() {
m.archiving = make(map[mastodon.ID]bool)
m.processing = make(map[mastodon.ID]int)
for {
select {
case <-m.clearTick.C:
Expand Down Expand Up @@ -139,6 +141,9 @@ func (m *Mastodon) Serve() error {
metrics.IncrementWayback(metrics.ServiceMastodon, metrics.StatusRequest)
bucket := pooling.Bucket{
Request: func(ctx context.Context) error {
m.Lock()
m.processing[n.Status.ID] += 1
m.Unlock()
if err := m.process(ctx, n.ID, n.Status); err != nil {
logger.Error("process failure, notification: %#v, error: %v", n, err)
return err
Expand All @@ -155,6 +160,7 @@ func (m *Mastodon) Serve() error {
m.pool.Put(bucket)
m.Lock()
delete(m.archiving, n.ID)
delete(m.processing, n.ID)
m.Unlock()
}()
}
Expand Down Expand Up @@ -206,7 +212,10 @@ func (m *Mastodon) process(ctx context.Context, id mastodon.ID, status *mastodon
urls := service.MatchURL(m.opts, text)
if len(urls) == 0 {
logger.Warn("archives failure, URL no found.")
m.ToMastodon(ctx, "URL no found", string(status.ID))
// Ensure response once
if m.processing[status.ID] == m.opts.PoolingSize() {
m.ToMastodon(ctx, "URL no found", string(status.ID))
}
return errors.New("Mastodon: URL no found")
}

Expand Down

0 comments on commit 6d24496

Please sign in to comment.