Unverified Commit 5d3776d4 authored by Diego Mello's avatar Diego Mello Committed by GitHub
Browse files

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

* Limit query to 50

* Remove observable
parent bc8d6b72
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment