Merge lp:~gcollura/ubuntu-calculator-app/reboot-delay-db-transactions into lp:ubuntu-calculator-app

Proposed by Giulio Collura on 2015-01-15
Status: Merged
Approved by: Riccardo Padovani on 2015-01-15
Approved revision: 64
Merged at revision: 63
Proposed branch: lp:~gcollura/ubuntu-calculator-app/reboot-delay-db-transactions
Merge into: lp:ubuntu-calculator-app
Diff against target: 53 lines (+24/-6)
1 file modified
app/engine/CalculationHistory.qml (+24/-6)
To merge this branch: bzr merge lp:~gcollura/ubuntu-calculator-app/reboot-delay-db-transactions
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2015-01-15
Riccardo Padovani 2015-01-15 Approve on 2015-01-15
Review via email: mp+246565@code.launchpad.net

Commit Message

Make use of Timer to delay db transactions.

Description of the Change

I've inserted a QML Timer with a execute list property that enqueue all db transactions and execute them after a while (500 ms) to avoid to block the UI when inserting or deleting calculations.

To post a comment you must log in.
64. By Giulio Collura on 2015-01-15

timer.start() is better than timer.restart() for various reasons

Riccardo Padovani (rpadovani) wrote :

After a talk with Giulio about timer.start() vs timer.restart() I approve this version.

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/engine/CalculationHistory.qml'
2--- app/engine/CalculationHistory.qml 2015-01-08 18:21:28 +0000
3+++ app/engine/CalculationHistory.qml 2015-01-15 13:45:32 +0000
4@@ -39,6 +39,18 @@
5 }
6 }
7
8+ Timer {
9+ id: timer
10+ interval: 500
11+ property var execute: []
12+ onTriggered: {
13+ for (var i = 0; i < execute.length; i++) {
14+ execute[i]();
15+ }
16+ execute = [];
17+ }
18+ }
19+
20 function openDatabase() {
21 // Check if the database was already opened
22 if (calculationHistoryDatabase !== null) return;
23@@ -107,7 +119,10 @@
24 var index = history.count - 1;
25 // TODO: move this function to a plave that retards the execution to
26 // improve performances
27- calculationHistory.addCalculationToDatabase(longFormula, result, date, index);
28+ timer.execute.push(function() {
29+ calculationHistory.addCalculationToDatabase(formula, result, date, index);
30+ });
31+ timer.start();
32 }
33
34 function addCalculationToDatabase(formula, result, date, index) {
35@@ -136,10 +151,13 @@
36
37 history.setProperty(id, "dbId", -1);
38
39- calculationHistoryDatabase.transaction(
40- function (tx) {
41- tx.executeSql('DELETE FROM Calculations WHERE dbId = ?', [dbId]);
42- }
43- );
44+ timer.execute.push(function () {
45+ calculationHistoryDatabase.transaction(
46+ function (tx) {
47+ tx.executeSql('DELETE FROM Calculations WHERE dbId = ?', [dbId]);
48+ }
49+ )
50+ });
51+ timer.start();
52 }
53 }

Subscribers

People subscribed via source and target branches