realm-js: Insert more then x documents blocks UI
Hi, I have strange problem. This is my sample code:
import React, { Component } from 'react';
import {
View,
Text,
TouchableNativeFeedback
} from 'react-native';
import Realm from 'realm';
Realm.clearTestState();
const ProductSchema = {
name: 'Product',
properties: {
variantId: 'string',
productId: 'string',
productNamePL: 'string',
productNameEN: { type: 'string', optional: true },
variantNamePL: 'string',
variantNameEN: { type: 'string', optional: true },
type: { type: 'int', optional: true },
unit: { type: 'int', optional: true },
tax: { type: 'int', optional: true },
pricePLN: { type: 'double', default: 0 },
priceEUR: { type: 'double', default: 0 },
priceUSD: { type: 'double', default: 0 },
priceRUB: { type: 'double', default: 0 },
priceCHF: { type: 'double', default: 0 },
priceGBP: { type: 'double', default: 0 }
}
};
const config = {
schema: [ProductSchema],
};
let realm = new Realm(config);
export default class App extends Component {
save() {
console.log('start')
try {
realm.write(() => {
for (const i = 0; i < 1175; i++) {
const product = {
variantId: 'variant' + i,
productId: 'product' + 1,
productNamePL: 'Variant name',
productNameEN: 'Variant name',
variantNamePL: 'Variant name',
variantNameEN: 'Variant name',
type: 1,
unit: 500,
tax: 8,
pricePLN: 10,
priceEUR: 8,
priceUSD: 5,
priceRUB: 9,
priceCHF: 3,
priceGBP: 12
};
realm.create('Product', product);
}
});
console.log('done');
} catch (e) {
console.log(e);
}
}
render() {
return (
<View style={{
backgroundColor: 'white',
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}}>
<TouchableNativeFeedback
onPress={this.save}
background={TouchableNativeFeedback.SelectableBackground()}>
<View style={{
width: 150,
height: 100,
backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center'
}}>
<Text>Tap</Text>
</View>
</TouchableNativeFeedback>
</View>
);
}
};
The problem is, when I insert more then 1175 documents (e.g. call twice save() or change i < 1176) the react-native UI is blocked. Checked on different devices, always number of documents which block UI is the same. This is not a fault of documents count, but documents size. When change some strings length - can insert more documents, etc. UI blocked only when I exceed number of documents while using app. When i close app and run again, I can insert next 1175. Realm has some limitation per session or it’s a bug? Realm 0.15.4 (the same problem on 0.14.3) React Native 0.38.0
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 20 (3 by maintainers)
I got the same problem. In my case, i tried to insert/update about 4000+ documents, the app get hang for a while then become normal. Any idea?
Below is the code which I use to insert records