Sending eventDB companion to avoid recreating it all the time
This commit is contained in:
+10
-10
@@ -31,22 +31,22 @@ import java.util.function.Consumer
|
|||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
|
|
||||||
open class BaseLargeCacheBenchmark {
|
open class BaseLargeCacheBenchmark {
|
||||||
fun getEventDB(): List<Event> {
|
companion object {
|
||||||
// This file includes duplicates
|
fun getEventDB(): List<Event> {
|
||||||
val fullDBInputStream = getInstrumentation().context.assets.open("nostr_vitor_startup_data.json")
|
// This file includes duplicates
|
||||||
|
val fullDBInputStream = getInstrumentation().context.assets.open("nostr_vitor_startup_data.json")
|
||||||
|
|
||||||
return JsonMapper.mapper.readValue<ArrayList<Event>>(
|
return JsonMapper.mapper.readValue<ArrayList<Event>>(
|
||||||
GZIPInputStream(fullDBInputStream),
|
GZIPInputStream(fullDBInputStream),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLargeCache(db: List<Event>): LargeCache<HexKey, Event> {
|
fun getLargeCache(db: List<Event>): LargeCache<HexKey, Event> {
|
||||||
val cache = LargeCache<HexKey, Event>()
|
val cache = LargeCache<HexKey, Event>()
|
||||||
|
|
||||||
db.forEach {
|
db.forEach { event ->
|
||||||
cache.getOrCreate(it.id) { key ->
|
cache.getOrCreate(event.id) { key -> event }
|
||||||
it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cache
|
return cache
|
||||||
|
|||||||
Reference in New Issue
Block a user