-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdk: optimize caching lists (so we don't fetch twice in a row).
- Loading branch information
Showing
5 changed files
with
74 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
package sdk | ||
|
||
import ( | ||
"strings" | ||
) | ||
import "time" | ||
|
||
// IsVirtualRelay returns true if the given normalized relay URL shouldn't be considered for outbox-model calculations. | ||
func IsVirtualRelay(url string) bool { | ||
if len(url) < 6 { | ||
// this is just invalid | ||
return true | ||
} | ||
var serial = 0 | ||
|
||
func pickNext(list []string) string { | ||
serial++ | ||
return list[serial%len(list)] | ||
} | ||
|
||
if strings.HasPrefix(url, "wss://feeds.nostr.band") || | ||
strings.HasPrefix(url, "wss://filter.nostr.wine") || | ||
strings.HasPrefix(url, "wss://cache") { | ||
return true | ||
func doThisNotMoreThanOnceAnHour(key string) (doItNow bool) { | ||
if _dtnmtoah == nil { | ||
go func() { | ||
_dtnmtoah = make(map[string]time.Time) | ||
for { | ||
time.Sleep(time.Minute * 10) | ||
_dtnmtoahLock.Lock() | ||
now := time.Now() | ||
for k, v := range _dtnmtoah { | ||
if v.Before(now) { | ||
delete(_dtnmtoah, k) | ||
} | ||
} | ||
_dtnmtoahLock.Unlock() | ||
} | ||
}() | ||
} | ||
|
||
return false | ||
_dtnmtoahLock.Lock() | ||
defer _dtnmtoahLock.Unlock() | ||
|
||
_, exists := _dtnmtoah[key] | ||
return !exists | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters