From 5d3776d4f1e040c71948a5df67b40d41abc5d87e Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 26 Feb 2021 13:49:21 -0300 Subject: [PATCH] [FIX] Limit new message list query size to 50 (#2947) * Limit query to 50 * Remove observable --- app/views/NewMessageView.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/app/views/NewMessageView.js b/app/views/NewMessageView.js index 31dcac51..7e2aa232 100644 --- a/app/views/NewMessageView.js +++ b/app/views/NewMessageView.js @@ -4,7 +4,6 @@ import { View, StyleSheet, FlatList, Text } from 'react-native'; import { connect } from 'react-redux'; -import orderBy from 'lodash/orderBy'; import { Q } from '@nozbe/watermelondb'; import * as List from '../containers/List'; @@ -27,6 +26,8 @@ import { createChannelRequest } from '../actions/createChannel'; import { goRoom } from '../utils/goRoom'; import SafeAreaView from '../containers/SafeAreaView'; +const QUERY_SIZE = 50; + const styles = StyleSheet.create({ button: { height: 46, @@ -74,25 +75,20 @@ class NewMessageView extends React.Component { }; } - componentWillUnmount() { - if (this.querySubscription && this.querySubscription.unsubscribe) { - this.querySubscription.unsubscribe(); - } - } - // eslint-disable-next-line react/sort-comp init = async() => { try { const db = database.active; - const observable = await db.collections + const chats = await db.collections .get('subscriptions') - .query(Q.where('t', 'd')) - .observeWithColumns(['room_updated_at']); + .query( + Q.where('t', 'd'), + Q.experimentalTake(QUERY_SIZE), + Q.experimentalSortBy('room_updated_at', Q.desc) + ) + .fetch(); - this.querySubscription = observable.subscribe((data) => { - const chats = orderBy(data, ['roomUpdatedAt'], ['desc']); - this.setState({ chats }); - }); + this.setState({ chats }); } catch (e) { log(e); }