[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
|
View, StyleSheet, FlatList, Text
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import orderBy from 'lodash/orderBy';
|
|
||||||
import { Q } from '@nozbe/watermelondb';
|
import { Q } from '@nozbe/watermelondb';
|
||||||
import * as List from '../containers/List';
|
import * as List from '../containers/List';
|
||||||
|
|
||||||
|
@ -27,6 +26,8 @@ import { createChannelRequest } from '../actions/createChannel';
|
||||||
import { goRoom } from '../utils/goRoom';
|
import { goRoom } from '../utils/goRoom';
|
||||||
import SafeAreaView from '../containers/SafeAreaView';
|
import SafeAreaView from '../containers/SafeAreaView';
|
||||||
|
|
||||||
|
const QUERY_SIZE = 50;
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
button: {
|
button: {
|
||||||
height: 46,
|
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
|
// eslint-disable-next-line react/sort-comp
|
||||||
init = async() => {
|
init = async() => {
|
||||||
try {
|
try {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const observable = await db.collections
|
const chats = await db.collections
|
||||||
.get('subscriptions')
|
.get('subscriptions')
|
||||||
.query(Q.where('t', 'd'))
|
.query(
|
||||||
.observeWithColumns(['room_updated_at']);
|
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) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue