[FIX] Limit new message list query size to 50 (#2947)
* Limit query to 50 * Remove observable
This commit is contained in:
parent
bc8d6b72f5
commit
5d3776d4f1
|
@ -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 });
|
||||
});
|
||||
} catch (e) {
|
||||
log(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue