[banshee] [extras/metrics] usage report import improvements



commit da418959cdbab6a7f9e6717d5a21e30829608372
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri Mar 26 10:17:28 2010 -0700

    [extras/metrics] usage report import improvements

 extras/metrics/Database.cs |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/extras/metrics/Database.cs b/extras/metrics/Database.cs
index 37e17b4..c0758d5 100644
--- a/extras/metrics/Database.cs
+++ b/extras/metrics/Database.cs
@@ -129,6 +129,8 @@ namespace metrics
             var last_config = LastReportNumber;
             long last_report_number = Int64.Parse (last_config.Value);
 
+            var max_report_size = 150 * 1024;
+
             db.BeginTransaction ();
             foreach (var file in System.IO.Directory.GetFiles ("data")) {
                 var match = report_number_regex.Match (file);
@@ -141,6 +143,12 @@ namespace metrics
                     continue;
                 }
 
+                var file_size = new System.IO.FileInfo (file).Length;
+                if (file_size > max_report_size) {
+                    Log.InformationFormat ("Skipping {0} because too large ({1:N0} KB compressed)", file, file_size/1024.0);
+                    continue;
+                }
+
                 last_report_number = num;
                 Log.DebugFormat ("Importing {0}", file);
 
@@ -166,6 +174,10 @@ namespace metrics
 
                     var metrics = o["Metrics"] as JsonObject;
                     foreach (string metric_name in metrics.Keys) {
+                        // Skip these; they are a ton of data, and really more for debug purposes
+                        if (metric_name == "Banshee/LongSqliteCommand")
+                            continue;
+
                         var samples = metrics[metric_name] as JsonArray;
 
                         string name = metric_name;
@@ -179,9 +191,16 @@ namespace metrics
                             sample_provider.Save (MultiUserSample.Import (db, user_id, name, (string)sample[0], (object)sample[1]));
                         }
                     }
+                    db.CommitTransaction ();
                 } catch (Exception e) {
                     Log.Exception (String.Format ("Failed to read {0}", file), e);
+                    db.RollbackTransaction ();
                 }
+
+                last_config.Value = last_report_number.ToString ();
+                Config.Save (last_config);
+
+                db.BeginTransaction ();
             }
             db.CommitTransaction ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]