Nacho Ruiz Martin
07/08/2024, 5:07 PMselectAsFlow
to return an empty array when 100% there’s data in the table that matches the filter?Jan
07/08/2024, 5:12 PMNacho Ruiz Martin
07/09/2024, 12:37 PMNacho Ruiz Martin
07/09/2024, 12:37 PMNacho Ruiz Martin
07/09/2024, 12:47 PMNacho Ruiz Martin
07/09/2024, 1:29 PMNacho Ruiz Martin
07/10/2024, 5:21 AMJan
07/10/2024, 2:28 PMNacho Ruiz Martin
07/10/2024, 2:58 PMJan
07/10/2024, 3:03 PMNacho Ruiz Martin
07/10/2024, 3:04 PMJan
07/10/2024, 3:17 PMfun main() {
GlobalScope.launch {
val supabase = createSupabaseClient(
supabaseUrl = "",
supabaseKey = ""
) {
install(Auth)
install(Realtime)
install(Postgrest)
}
val flow = supabase.from("messages").selectAsFlow(Message::id)
flow.collect {
println(it)
}
}
}
Can you share your code?Nacho Ruiz Martin
07/10/2024, 3:20 PMNacho Ruiz Martin
07/10/2024, 3:20 PM@OptIn(SupabaseExperimental::class)
private suspend fun getPubsByManagerStream(userId: String): Flow<List<Pub>> =
supabase.from("pub_admin")
.selectAsFlow(
primaryKeys = listOf(PubAdmin::pub, PubAdmin::user),
filter = FilterOperation("user", FilterOperator.EQ, userId)
)
.flatMapLatest { adminPubs ->
if (adminPubs.isEmpty()) flowOf(emptyList())
else combine(adminPubs.map { (pubId, _) -> pubsService.getPubDetailsStream(pubId) }) {
it.toList()
}
}
Jan
07/10/2024, 3:22 PMgetPubDetailsStream
also using realtime?Nacho Ruiz Martin
07/10/2024, 3:22 PM@OptIn(SupabaseExperimental::class)
override suspend fun getPubDetailsStream(pubId: Int): Flow<Pub> =
supabase.from(tableName)
.selectSingleValueAsFlow(Pub::id) {
Pub::id eq pubId
}
Nacho Ruiz Martin
07/10/2024, 3:23 PMNacho Ruiz Martin
07/10/2024, 3:24 PMJan
07/10/2024, 3:29 PM.flatMapLatest { adminPubs ->
if (adminPubs.isEmpty()) flowOf(emptyList())
else combine(adminPubs.map { (pubId, _) -> pubsService.getPubDetailsStream(pubId) }) {
it.toList()
}
}
So for every change you are basically retrieving details & listening for changes on them each on their own?Nacho Ruiz Martin
07/10/2024, 3:31 PMNacho Ruiz Martin
07/10/2024, 3:31 PMJan
07/10/2024, 3:35 PMselectSingleValueAsFlow
for every pub on every change. Not sure if these unused flows get cancelled at all 🤔Jan
07/10/2024, 3:46 PMRealtime#subscriptions
to check how many channels are used. That would be one for getPubsByManagerStream
and one each for getPubDetailsStream
callsNacho Ruiz Martin
07/10/2024, 5:14 PMNacho Ruiz Martin
07/10/2024, 5:15 PMNacho Ruiz Martin
07/14/2024, 10:48 AM