perf: don't continuously attempt to fetch old profiles

Changelog-Changed: Save bandwidth by only fetching new profiles after a certain amount of time
This commit is contained in:
William Casarin
2023-10-23 10:31:47 +08:00
parent bbccc27a26
commit 76508dbbfd
12 changed files with 86 additions and 48 deletions

View File

@@ -22,11 +22,11 @@ class FollowingModel {
self.hashtags = hashtags
}
func get_filter() -> NostrFilter {
func get_filter<Y>(txn: NdbTxn<Y>) -> NostrFilter {
var f = NostrFilter(kinds: [.metadata])
f.authors = self.contacts.reduce(into: Array<Pubkey>()) { acc, pk in
// don't fetch profiles we already have
if damus_state.profiles.has_fresh_profile(id: pk) {
if damus_state.profiles.has_fresh_profile(id: pk, txn: txn) {
return
}
acc.append(pk)
@@ -34,8 +34,8 @@ class FollowingModel {
return f
}
func subscribe() {
let filter = get_filter()
func subscribe<Y>(txn: NdbTxn<Y>) {
let filter = get_filter(txn: txn)
if (filter.authors?.count ?? 0) == 0 {
needs_sub = false
return