question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Insert more then x documents blocks UI

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
daominhsangvncommented, Oct 24, 2017

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?

1reaction
Udbhav12commented, Nov 25, 2020

Nope, it’s the same way that I open my realm here. Can you share your block code where you call the realm method? I have a hunch of what might be.

Below is the code which I use to insert records

const schemaVersion = 110;

const schema = [TABLE1 ,....];
var encryptionKey = new Int8Array(64);

let realm = new Realm({
    schemaVersion,
    schema,
    encryptionKey,
    shouldCompactOnLaunch: (totalBytes,usedBytes)=>{
		return true
	}
});

//array consists of 25k records where each record has 30 properties
array.forEach(data => realm.create(tableName, data, true));

Read more comments on GitHub >

github_iconTop Results From Across the Web

About Modular Blocks field - Contentstack
Modular Blocks is a field that allows content managers to dynamically create and modify components of a page or app on the go....
Read more >
Build FixedDocument without blocking UI - wpf - Stack Overflow
I'm generating a document for DocumentViewer. It's slow, so I want to free the UI thread. Using async/await I get an exception saying,...
Read more >
BlockUIContainer Class (System.Windows.Documents)
A block-level flow content element which enables UIElement elements (i.e. a Button) to be embedded (hosted) in flow content.
Read more >
Layout and the containing block - CSS: Cascading Style Sheets
The size and position of an element are often impacted by its containing block. Most often, the containing block is the content area...
Read more >
Review UI Overview
Reviewing changes is an important task and the Gerrit Web UI provides many ... The change metadata block contains detailed information about the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found