[chronojump] Encoder update curves on SQL as transaction: fast
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Encoder update curves on SQL as transaction: fast
- Date: Sun, 2 Nov 2014 23:17:59 +0000 (UTC)
commit 9aeae39d884a5778d9991ef8cb7790a5a128a965
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Nov 3 00:17:36 2014 +0100
Encoder update curves on SQL as transaction: fast
src/gui/encoder.cs | 18 ++----------------
src/sqlite/encoder.cs | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 2ce5c12..59de8fc 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -850,22 +850,8 @@ public partial class ChronoJumpWindow
false, true);
//update on database the curves that have been selected/deselected
- int count = 0;
- int countActive = 0;
-
- Sqlite.Open();
- foreach(EncoderSQL eSQL in data) {
- if(eSQL.status != checkboxes[count]) {
- eSQL.status = checkboxes[count];
- SqliteEncoder.Update(true, eSQL);
- }
-
- count ++;
-
- if(eSQL.status == "active")
- countActive ++;
- }
- Sqlite.Close();
+ //doing it as a transaction: FAST
+ int countActive = SqliteEncoder.UpdateTransaction(data, checkboxes);
int activeCurvesNum = getActiveCurvesNum(data);
label_encoder_user_curves_active_num.Text = activeCurvesNum.ToString();
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 15407ee..889a682 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -141,6 +141,41 @@ class SqliteEncoder : Sqlite
Sqlite.Close();
}
+ public static int UpdateTransaction(ArrayList data, string [] checkboxes)
+ {
+ int count = 0;
+ int countActive = 0;
+
+ Log.WriteLine("Starting transaction");
+ Sqlite.Open();
+
+ using(SqliteTransaction tr = dbcon.BeginTransaction())
+ {
+ using (SqliteCommand dbcmdTr = dbcon.CreateCommand())
+ {
+ dbcmdTr.Transaction = tr;
+
+ foreach(EncoderSQL eSQL in data) {
+ if(eSQL.status != checkboxes[count]) {
+ eSQL.status = checkboxes[count];
+
+ SqliteEncoder.Update(true, eSQL);
+ }
+
+ count ++;
+
+ if(eSQL.status == "active")
+ countActive ++;
+ }
+ }
+ tr.Commit();
+ }
+
+ Sqlite.Close();
+ Log.WriteLine("Ended transaction");
+ return countActive;
+ }
+
//pass uniqueID value and then will return one record. do like this:
//EncoderSQL eSQL = (EncoderSQL) SqliteEncoder.Select(false, myUniqueID, 0, 0, 0, "",
EncoderSQL.Eccons.ALL, false, true)[0];
//don't care for the 0, 0, 0 because selection will be based on the myUniqueID and only one row will
be returned
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]