mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 23:04:29 +00:00
use separate transaction per insertion for sql
This commit is contained in:
parent
1614d02df0
commit
e0a6bc0ab1
@ -37,7 +37,7 @@ const TestObjectListSchema = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const numTestObjects = 100;
|
const numTestObjects = 2000;
|
||||||
const numBatchTestObjects = numTestObjects * 100;
|
const numBatchTestObjects = numTestObjects * 100;
|
||||||
const numRepeats = 1;
|
const numRepeats = 1;
|
||||||
const numQueryBuckets = 5;
|
const numQueryBuckets = 5;
|
||||||
@ -84,11 +84,11 @@ class RealmTests extends Tests {
|
|||||||
|
|
||||||
async insertions() {
|
async insertions() {
|
||||||
var realm = this.realm;
|
var realm = this.realm;
|
||||||
realm.write(() => {
|
for (let i = 0; i < numTestObjects; i++) {
|
||||||
for (let i = 0; i < numTestObjects; i++) {
|
realm.write(() => {
|
||||||
realm.create("TestObject", { int: i % numQueryBuckets, double: i, date: new Date(i), string: "" + i });
|
realm.create("TestObject", { int: i % numQueryBuckets, double: i, date: new Date(i), string: "" + i });
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async batchInsert(objects) {
|
async batchInsert(objects) {
|
||||||
@ -226,6 +226,15 @@ class RNSqliteTests extends Tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async insertions() {
|
async insertions() {
|
||||||
|
for (let i = 0; i < numTestObjects; i++) {
|
||||||
|
let values = ["" + i, i % numQueryBuckets, i, new Date(i).getTime()];
|
||||||
|
await this.db.transaction((tx) => {
|
||||||
|
tx.executeSql('INSERT INTO t1 (string, int, double, date) VALUES (?,?,?,?);', values);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async batchInsert(objects) {
|
||||||
await this.db.transaction((tx) => {
|
await this.db.transaction((tx) => {
|
||||||
for (let i = 0; i < numTestObjects; i++) {
|
for (let i = 0; i < numTestObjects; i++) {
|
||||||
let values = ["" + i, i % numQueryBuckets, i, new Date(i).getTime()];
|
let values = ["" + i, i % numQueryBuckets, i, new Date(i).getTime()];
|
||||||
@ -234,29 +243,6 @@ class RNSqliteTests extends Tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async batchInsert(objects) {
|
|
||||||
await this.db.transaction((tx) => {
|
|
||||||
for (var obj of objects) {
|
|
||||||
let values = [obj.string, obj.int, obj.double, obj.date.getTime(), obj.string];
|
|
||||||
tx.executeSql('INSERT INTO t1 (string, int, double, date) VALUES (?,?,?,?);', values);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
var allValues = [];
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
var object = this.testObjects[i];
|
|
||||||
var values = Object.keys(object).map((key) => object[key]);
|
|
||||||
Array.prototype.push.apply(allValues, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.db.transaction((tx) => {
|
|
||||||
var sql = "INSERT INTO t1 SELECT ? AS string, ? AS int, ? AS double, ? AS date)" +
|
|
||||||
"UNION ALL SELECT ?, ?, ?, ?".repeat(count - 1);
|
|
||||||
tx.executeSql(sql, allValues);
|
|
||||||
});*/
|
|
||||||
|
|
||||||
async enumeration() {
|
async enumeration() {
|
||||||
await this.db.readTransaction(async (tx) => {
|
await this.db.readTransaction(async (tx) => {
|
||||||
let [, results] = await tx.executeSql('SELECT * FROM t1;')
|
let [, results] = await tx.executeSql('SELECT * FROM t1;')
|
||||||
@ -337,7 +323,7 @@ class ReactNativeBenchmarks extends Component {
|
|||||||
|
|
||||||
_renderRow(rowData) {
|
_renderRow(rowData) {
|
||||||
return (
|
return (
|
||||||
<Text style={styles.item}>{rowData.join('\t')}</Text>
|
<Text style={styles.item}>{rowData.join('\t\t')}</Text>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,6 +346,7 @@ class ReactNativeBenchmarks extends Component {
|
|||||||
|
|
||||||
async _runTestsAsync() {
|
async _runTestsAsync() {
|
||||||
var data = [apiTests.map((api) => api.name)];
|
var data = [apiTests.map((api) => api.name)];
|
||||||
|
data[0].splice(0, 0, "\t\t");
|
||||||
for (let test of tests) {
|
for (let test of tests) {
|
||||||
data.push([test]);
|
data.push([test]);
|
||||||
this.setState({
|
this.setState({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user