Narrowing the redownloads of reactions down.

This commit is contained in:
Vitor Pamplona 2023-11-20 18:58:25 -05:00
parent 5a9d6929e5
commit 9acad8b3f5
5 changed files with 15 additions and 3 deletions

View File

@ -61,7 +61,7 @@ abstract class NostrDataSource(val debugName: String) {
if (type == Relay.StateType.EOSE && subscriptionId != null && subscriptionId in subscriptions.keys) {
// updates a per subscripton since date
subscriptions[subscriptionId]?.updateEOSE(
TimeUtils.fiveMinutesAgo(), // in case people's clock is slighly off.
TimeUtils.oneMinuteAgo(), // in case people's clock is slighly off.
relay.url
)
}

View File

@ -156,6 +156,15 @@ object NostrSingleEventDataSource : NostrDataSource("SingleEventFeed") {
}
}
addressesToWatch.forEach {
val eose = it.lastReactionsDownloadTime[relayUrl]
if (eose == null) {
it.lastReactionsDownloadTime = it.lastReactionsDownloadTime + Pair(relayUrl, EOSETime(time))
} else {
eose.time = time
}
}
// Many relays operate with limits in the amount of filters.
// As information comes, the filters will be rotated to get more data.
invalidateFilters()

View File

@ -29,6 +29,8 @@ object OnlineChecker {
return checkOnlineCache.get(url).online
}
Log.d("OnlineChecker", "isOnline $url")
return try {
val request = Request.Builder()
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")

View File

@ -207,7 +207,7 @@ class Relay(
"EVENT" -> {
val event = Event.fromJson(msgArray.get(2))
// Log.w("Relay", "Relay onEVENT $url, $channel")
Log.w("Relay", "Relay onEVENT $url, $channel ${msgArray.get(2)}")
listeners.forEach {
it.onEvent(this@Relay, channel, event)
if (afterEOSE) {
@ -276,7 +276,7 @@ class Relay(
if (filters.isNotEmpty()) {
val request =
"""["REQ","$requestId",${filters.take(10).joinToString(",") { it.filter.toJson(url) }}]"""
// println("FILTERSSENT $url $request")
Log.d("Relay", "onFilterSent $url $requestId $request")
socket?.send(request)
eventUploadCounterInBytes += request.bytesUsedInMemory()
afterEOSE = false

View File

@ -11,6 +11,7 @@ object TimeUtils {
const val oneWeek = 7 * oneDay
fun now() = System.currentTimeMillis() / 1000
fun oneMinuteAgo() = now() - oneMinute
fun fiveMinutesAgo() = now() - fiveMinutes
fun oneHourAgo() = now() - oneHour
fun oneHourAhead() = now() + oneHour