Permalink
Browse files

Speedup loading of external files.

  • Loading branch information...
1 parent 79a404a commit 3d3fb2c200b2bd8b5a0de0c2c7bd973d95a84479 @DaveDavenport committed Apr 9, 2012
Showing with 35 additions and 1 deletion.
  1. +33 −1 EnergyPoint.vala
  2. +2 −0 main.vala
View
@@ -19,6 +19,8 @@ class EnergyStorage
// Prepared statements.
private Statement insert_ep;
+ private Statement transaction_start;
+ private Statement transaction_stop;
/**
* Create a new Storage.
@@ -49,6 +51,26 @@ class EnergyStorage
{
GLib.error("Failed to create stmt: %s", db.errmsg());
}
+
+
+ const string transaction_start_str = """
+ BEGIN TRANSACTION;
+ """;
+ if(db.prepare_v2(insert_db_str,-1, out insert_ep) == 1)
+ {
+ GLib.error("Failed to create stmt: %s", db.errmsg());
+ }
+ const string transaction_stop_str = """
+ COMMIT;
+ """;
+ if(db.prepare_v2(transaction_start_str,-1, out transaction_start) == 1)
+ {
+ GLib.error("Failed to create stmt: %s", db.errmsg());
+ }
+ if(db.prepare_v2(transaction_stop_str,-1, out transaction_stop) == 1)
+ {
+ GLib.error("Failed to create stmt: %s", db.errmsg());
+ }
}
/**
@@ -93,6 +115,7 @@ class EnergyStorage
DateTime dt = new DateTime.from_timeval_local(val);
var val_obj = obj.get_array_member("val");
+
foreach(weak Json.Node el in val_obj.get_elements())
{
string? a = el.get_string();
@@ -103,11 +126,20 @@ class EnergyStorage
if(this.add_point(ep)) retv++;
}
dt = dt.add_seconds((double)60.0);
-
}
return retv;
}
+
+ public void start_transaction()
+ {
+ transaction_start.step();
+ }
+ public void stop_transaction()
+ {
+ transaction_stop.step();
+ }
+
/**
*
*/
View
@@ -6,6 +6,7 @@ using GLib;
void importing_files(EnergyStorage es, string[] argv, uint offset)
{
uint total = 0;
+ es.start_transaction();
for(uint i = offset ; i < argv.length; i++)
{
stdout.printf("Importing file: '%s': ", argv[i]);
@@ -22,6 +23,7 @@ void importing_files(EnergyStorage es, string[] argv, uint offset)
stdout.printf("Failed to import file: '%s'\n", e.message);
}
}
+ es.stop_transaction();
stdout.printf("Imported a total of %u points\n", total);
}

0 comments on commit 3d3fb2c

Please sign in to comment.