← Back to team overview

zeitgeist team mailing list archive

[Merge] lp:~seif/zeitgeist/bb-extract-methods into lp:~zeitgeist/zeitgeist/bluebird

 

Seif Lotfy has proposed merging lp:~seif/zeitgeist/bb-extract-methods into lp:~zeitgeist/zeitgeist/bluebird.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)

For more details, see:
https://code.launchpad.net/~seif/zeitgeist/bb-extract-methods/+merge/80316

Extracted extract event and subj generation out of get_events into get_event_from_row and get_subject_from_row
-- 
https://code.launchpad.net/~seif/zeitgeist/bb-extract-methods/+merge/80316
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~seif/zeitgeist/bb-extract-methods into lp:~zeitgeist/zeitgeist/bluebird.
=== modified file 'src/engine.vala'
--- src/engine.vala	2011-10-20 11:20:36 +0000
+++ src/engine.vala	2011-10-25 10:46:39 +0000
@@ -67,6 +67,49 @@
         return extension_collection.get_extension_names ();
     }
 
+    private Event get_event_from_row (Sqlite.Statement stmt, uint32 event_id)
+    {
+        Event? event = new Event ();
+        event.id = event_id;
+        event.timestamp = stmt.column_int64 (EventViewRows.TIMESTAMP);
+        event.interpretation = interpretations_table.get_value (
+            stmt.column_int (EventViewRows.INTERPRETATION));
+        event.manifestation = manifestations_table.get_value (
+            stmt.column_int (EventViewRows.MANIFESTATION));
+        event.actor = actors_table.get_value (
+            stmt.column_int (EventViewRows.ACTOR));
+        event.origin = stmt.column_text (
+            EventViewRows.EVENT_ORIGIN_URI);
+        // Load payload
+        unowned uint8[] data = (uint8[])
+            stmt.column_blob(EventViewRows.PAYLOAD);
+        data.length = stmt.column_bytes(EventViewRows.PAYLOAD);
+        if (data != null)
+        {
+            event.payload = new ByteArray();
+            event.payload.append(data);
+        }
+        return event;
+    }
+
+    private Subject get_subject_from_row (Sqlite.Statement stmt)
+    {
+        Subject? subject = new Subject ();
+        subject.uri = stmt.column_text (EventViewRows.SUBJECT_URI);
+        subject.text = stmt.column_text (EventViewRows.SUBJECT_TEXT);
+        subject.storage = stmt.column_text (EventViewRows.SUBJECT_STORAGE);
+        subject.origin = stmt.column_text (EventViewRows.SUBJECT_ORIGIN_URI);
+        subject.current_uri = stmt.column_text (
+            EventViewRows.SUBJECT_CURRENT_URI);
+        subject.interpretation = interpretations_table.get_value (
+            stmt.column_int (EventViewRows.SUBJECT_INTERPRETATION));
+        subject.manifestation = manifestations_table.get_value (
+            stmt.column_int (EventViewRows.SUBJECT_MANIFESTATION));
+        subject.mimetype = mimetypes_table.get_value (
+            stmt.column_int (EventViewRows.SUBJECT_MIMETYPE));
+        return subject;
+    }
+
     public GenericArray<Event?> get_events(uint32[] event_ids,
             BusName? sender=null) throws EngineError
     {
@@ -76,11 +119,15 @@
         //  to enhance the performance of SQLite now, and event processing
         //  will be faster now being C.
 
-        Sqlite.Statement stmt;
-        int rc;
-
         if (event_ids.length == 0)
             return new GenericArray<Event?> ();
+
+        var events = new HashTable<uint32, Event?> (direct_hash, direct_equal);
+
+        // Set up SQL statement
+        Sqlite.Statement stmt;
+        int rc;
+
         var sql_event_ids = database.get_sql_string_from_event_ids (event_ids);
         string sql = """
             SELECT * FROM event_view
@@ -90,52 +137,17 @@
         rc = db.prepare_v2 (sql, -1, out stmt);
         database.assert_query_success (rc, "SQL error");
 
-        var events = new HashTable<uint32, Event?> (direct_hash, direct_equal);
-
+        // Create Events and Subjects from rows
         while ((rc = stmt.step ()) == Sqlite.ROW)
         {
             uint32 event_id = (uint32) stmt.column_int64 (EventViewRows.ID);
             Event? event = events.lookup (event_id);
             if (event == null)
             {
-                event = new Event ();
-                event.id = event_id;
-                event.timestamp = stmt.column_int64 (EventViewRows.TIMESTAMP);
-                event.interpretation = interpretations_table.get_value (
-                    stmt.column_int (EventViewRows.INTERPRETATION));
-                event.manifestation = manifestations_table.get_value (
-                    stmt.column_int (EventViewRows.MANIFESTATION));
-                event.actor = actors_table.get_value (
-                    stmt.column_int (EventViewRows.ACTOR));
-                event.origin = stmt.column_text (
-                    EventViewRows.EVENT_ORIGIN_URI);
-
-                // Load payload
-                unowned uint8[] data = (uint8[])
-                    stmt.column_blob(EventViewRows.PAYLOAD);
-                data.length = stmt.column_bytes(EventViewRows.PAYLOAD);
-                if (data != null)
-                {
-                    event.payload = new ByteArray();
-                    event.payload.append(data);
-                }
+                event = get_event_from_row(stmt, event_id);
                 events.insert (event_id, event);
             }
-
-            Subject subject = new Subject ();
-            subject.uri = stmt.column_text (EventViewRows.SUBJECT_URI);
-            subject.text = stmt.column_text (EventViewRows.SUBJECT_TEXT);
-            subject.storage = stmt.column_text (EventViewRows.SUBJECT_STORAGE);
-            subject.origin = stmt.column_text (EventViewRows.SUBJECT_ORIGIN_URI);
-            subject.current_uri = stmt.column_text (
-                EventViewRows.SUBJECT_CURRENT_URI);
-            subject.interpretation = interpretations_table.get_value (
-                stmt.column_int (EventViewRows.SUBJECT_INTERPRETATION));
-            subject.manifestation = manifestations_table.get_value (
-                stmt.column_int (EventViewRows.SUBJECT_MANIFESTATION));
-            subject.mimetype = mimetypes_table.get_value (
-                stmt.column_int (EventViewRows.SUBJECT_MIMETYPE));
-
+            Subject subject = get_subject_from_row(stmt);
             event.add_subject(subject);
         }
         if (rc != Sqlite.DONE)
@@ -144,6 +156,7 @@
                 rc, db.errmsg ());
         }
 
+        // Sort events according to the sequence of event_ids
         var results = new GenericArray<Event?> ();
         results.length = event_ids.length;
         int i = 0;


Follow ups