mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-28 18:51:45 +01:00
Moving URL Preview fetcher to thread + running over a given feed list.
This commit is contained in:
parent
7d18f36e3e
commit
ff529a920e
@ -119,8 +119,6 @@ object LocalCache {
|
|||||||
it.addReply(note)
|
it.addReply(note)
|
||||||
}
|
}
|
||||||
|
|
||||||
UrlCachedPreviewer.preloadPreviewsFor(note)
|
|
||||||
|
|
||||||
refreshObservers()
|
refreshObservers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.vitorpamplona.amethyst.service
|
package com.vitorpamplona.amethyst.service
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
|
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelHideMessageEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelHideMessageEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
||||||
@ -11,6 +13,12 @@ import com.vitorpamplona.amethyst.service.model.RepostEvent
|
|||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
import kotlin.time.ExperimentalTime
|
||||||
|
import kotlin.time.measureTimedValue
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import nostr.postr.events.ContactListEvent
|
import nostr.postr.events.ContactListEvent
|
||||||
import nostr.postr.events.DeletionEvent
|
import nostr.postr.events.DeletionEvent
|
||||||
import nostr.postr.events.Event
|
import nostr.postr.events.Event
|
||||||
@ -104,8 +112,25 @@ abstract class NostrDataSource<T>(val debugName: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalTime::class)
|
||||||
fun loadTop(): List<T> {
|
fun loadTop(): List<T> {
|
||||||
return feed().take(100)
|
val returningList = feed().take(100)
|
||||||
|
|
||||||
|
// prepare previews
|
||||||
|
val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||||
|
scope.launch {
|
||||||
|
loadPreviews(returningList)
|
||||||
|
}
|
||||||
|
|
||||||
|
return returningList
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun loadPreviews(list: List<T>) {
|
||||||
|
list.forEach {
|
||||||
|
if (it is Note) {
|
||||||
|
UrlCachedPreviewer.preloadPreviewsFor(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestNewChannel(): Channel {
|
fun requestNewChannel(): Channel {
|
||||||
|
@ -70,7 +70,6 @@ object NostrSingleEventDataSource: NostrDataSource<Note>("SingleEventFeed") {
|
|||||||
|
|
||||||
fun add(eventId: String) {
|
fun add(eventId: String) {
|
||||||
eventsToWatch = eventsToWatch.plus(eventId)
|
eventsToWatch = eventsToWatch.plus(eventId)
|
||||||
println("AAA: Event Watching ${eventsToWatch.size}")
|
|
||||||
resetFilters()
|
resetFilters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@ object NostrSingleUserDataSource: NostrDataSource<Note>("SingleUserFeed") {
|
|||||||
|
|
||||||
fun add(userId: String) {
|
fun add(userId: String) {
|
||||||
usersToWatch = usersToWatch.plus(userId)
|
usersToWatch = usersToWatch.plus(userId)
|
||||||
println("AAA: User Watching ${usersToWatch.size}")
|
|
||||||
resetFilters()
|
resetFilters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user