[FIX] Limit new message list query size to 50 (#2947)

* Limit query to 50

* Remove observable
This commit is contained in:
Diego Mello 2021-02-26 13:49:21 -03:00 committed by GitHub
parent bc8d6b72f5
commit 5d3776d4f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 14 deletions

View File

@ -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);
}