Seif Lotfy has proposed merging lp:~zeitgeist/zeitgeist/bb-memory into 
lp:~zeitgeist/zeitgeist/bluebird.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)

For more details, see:
https://code.launchpad.net/~zeitgeist/zeitgeist/bb-memory/+merge/79755

This is based on Juerg's proposed changes to reduce the memory consumption... 
according to him there could be fragmentation in our current code that don't 
allow some memory to be freed until the process dies.
-- 
https://code.launchpad.net/~zeitgeist/zeitgeist/bb-memory/+merge/79755
Your team Zeitgeist Framework Team is requested to review the proposed merge of 
lp:~zeitgeist/zeitgeist/bb-memory into lp:~zeitgeist/zeitgeist/bluebird.
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala	2011-10-17 07:46:27 +0000
+++ src/datamodel.vala	2011-10-19 01:24:25 +0000
@@ -498,7 +498,7 @@
             return vb.end ();
         }
 
-        private static Variant get_null_event_variant ()
+        public static Variant get_null_event_variant ()
         {
             var vb = new VariantBuilder (new VariantType ("("+Utils.SIG_EVENT+")"));
             vb.open (new VariantType ("as"));

=== modified file 'src/engine.vala'
--- src/engine.vala	2011-10-13 16:12:48 +0000
+++ src/engine.vala	2011-10-19 01:24:25 +0000
@@ -67,7 +67,7 @@
         return extension_collection.get_extension_names ();
     }
 
-    public GenericArray<Event?> get_events(uint32[] event_ids,
+    public Variant get_events(uint32[] event_ids,
             BusName? sender=null) throws EngineError
     {
         // TODO: Consider if we still want the cache. This should be done
@@ -76,85 +76,129 @@
         //  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?> ();
+            return new Variant.array (null, null);
+
+        Sqlite.Statement stmt;
+        int rc;
+
         var sql_event_ids = database.get_sql_string_from_event_ids (event_ids);
         string sql = """
             SELECT * FROM event_view
             WHERE id IN (%s)
             """.printf (sql_event_ids);
-
         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);
-
+        var events = new HashTable<uint32, VariantBuilder>
+                                                    (direct_hash, direct_equal);
+        var payloads = new HashTable<uint32, ByteArray>
+                                                    (direct_hash, direct_equal);
+        var event_variants = new HashTable<uint32, Variant>
+                                                    (direct_hash, direct_equal);
+        //Store rows in Hashtables
         while ((rc = stmt.step ()) == Sqlite.ROW)
         {
+            
             uint32 event_id = (uint32) stmt.column_int64 (EventViewRows.ID);
-            Event? event = events.lookup (event_id);
+            string s;
+            
+            var 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
+                var vb = new VariantBuilder 
+                                    (new VariantType ("("+Utils.SIG_EVENT+")"));
+                vb.open (new VariantType ("as"));
+                
+                s = event_id.to_string();
+                vb.add ("s", s != null ? s : "");
+                s = stmt.column_int64 (EventViewRows.TIMESTAMP).to_string();
+                vb.add ("s", s != null ? s : "");
+                s = interpretations_table.get_value (stmt.column_int (EventViewRows.INTERPRETATION));
+                vb.add ("s", s != null ? s : "");
+                s = manifestations_table.get_value (stmt.column_int (EventViewRows.MANIFESTATION));
+                vb.add ("s", s != null ? s : "");
+                s = actors_table.get_value (stmt.column_int (EventViewRows.ACTOR));
+                vb.add ("s", s != null ? s : "");
+                s = stmt.column_text (EventViewRows.EVENT_ORIGIN_URI);
+                vb.add ("s", s != null ? s : "");
+                vb.close();
+                
+                vb.open (new VariantType ("aas"));
+                
+                events.insert(event_id, vb);
+                
                 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);
+                    var payload = new ByteArray();
+                    payload.append(data);
+                    payloads.insert(event_id, payload);
                 }
-                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));
-
-            event.add_subject(subject);
+            
+            var svb = new VariantBuilder (new VariantType ("as"));
+            
+            s = stmt.column_text (EventViewRows.SUBJECT_URI);
+            svb.add ("s", s != null ? s : "");
+            s = interpretations_table.get_value (stmt.column_int (EventViewRows.SUBJECT_INTERPRETATION));
+            svb.add ("s", s != null ? s : "");
+            s = manifestations_table.get_value (stmt.column_int (EventViewRows.SUBJECT_MANIFESTATION));
+            svb.add ("s", s != null ? s : "");
+            s = stmt.column_text (EventViewRows.SUBJECT_ORIGIN_URI);
+            svb.add ("s", s != null ? s : "");
+            s = mimetypes_table.get_value (stmt.column_int (EventViewRows.SUBJECT_MIMETYPE));
+            svb.add ("s", s != null ? s : "");
+            s = stmt.column_text (EventViewRows.SUBJECT_TEXT);
+            svb.add ("s", s != null ? s : "");
+            s = stmt.column_text (EventViewRows.SUBJECT_STORAGE);
+            svb.add ("s", s != null ? s : "");
+            s = stmt.column_text (EventViewRows.SUBJECT_CURRENT_URI);
+            svb.add ("s", s != null ? s : "");
+            
+            events.lookup(event_id).add_value(svb.end());
         }
         if (rc != Sqlite.DONE)
         {
             throw new EngineError.DATABASE_ERROR ("Error: %d, %s\n", 
                 rc, db.errmsg ());
         }
-
-        var results = new GenericArray<Event?> ();
-        results.length = event_ids.length;
-        int i = 0;
+        
+        foreach (var id in events.get_keys())
+        {
+            var vb = events.lookup (id);
+            if (vb != null)
+            {
+                vb.close();
+                var payload = payloads.lookup(id);
+                if (payload != null)
+                {
+                    Variant payload_variant = Variant.new_from_data<ByteArray> (
+                        new VariantType ("ay"), payload.data, false, payload);
+                    // FIXME: somehow adding the payload_variant is not working
+                    vb.add_value (payload_variant);
+                }
+                else
+                {
+                    vb.open (new VariantType ("ay"));
+                    vb.close ();
+                }
+            }
+            event_variants.insert(id, vb.end());
+        }
+        
+        var results = new VariantBuilder (new VariantType ("a("+Utils.SIG_EVENT+")"));
         foreach (var id in event_ids)
         {
-            results.set(i++, events.lookup (id));
+            var event = event_variants.lookup (id);
+            if (event != null)
+                results.add_value (event);
+            else
+                results.add_value (Events.get_null_event_variant ());
         }
-
-        extension_collection.call_post_get_events (results, sender);
-
-        return results;
+        return results.end();
     }
 
     public uint32[] find_event_ids (TimeRange time_range,
@@ -344,7 +388,7 @@
         return event_ids;
     }
 
-    public GenericArray<Event?> find_events (TimeRange time_range,
+    public Variant find_events (TimeRange time_range,
         GenericArray<Event> event_templates,
         uint storage_state, uint max_events, uint result_type,
         BusName? sender=null) throws EngineError

=== modified file 'src/extension-collection.vala'
--- src/extension-collection.vala	2011-10-12 10:53:00 +0000
+++ src/extension-collection.vala	2011-10-19 01:24:25 +0000
@@ -134,15 +134,14 @@
             assert (num_events == events.length);
         }
 
-        public void call_post_get_events (GenericArray<Event?> events,
+        public void call_post_get_events (Variant events,
             BusName? sender)
         {
-            int num_events = events.length;
+            // GVariant is immutable, no need to verify that extensions don't modify it
             for (int i = 0; i < extensions.length; ++i)
             {
                 extensions[i].post_get_events (events, sender);
             }
-            assert (num_events == events.length);
         }
 
         public unowned uint32[] call_pre_delete_events (uint32[] event_ids,

=== modified file 'src/extension.vala'
--- src/extension.vala	2011-09-25 15:58:52 +0000
+++ src/extension.vala	2011-10-19 01:24:25 +0000
@@ -91,10 +91,10 @@
          * The event may also be changed in place or fully substituted for
          * another event.
          *
-         * @param events: A GenericArray of Event instances
+         * @param events: A GVariant with event instances (signature a(asaasay))
          * @param sender: The D-Bus bus name of the client or NULL
          */
-         public virtual void post_get_events (GenericArray<Event?> events,
+         public virtual void post_get_events (Variant events,
             BusName? sender)
          {
          }

=== modified file 'src/zeitgeist-daemon.vala'
--- src/zeitgeist-daemon.vala	2011-10-13 15:59:53 +0000
+++ src/zeitgeist-daemon.vala	2011-10-19 01:24:25 +0000
@@ -129,9 +129,9 @@
             throws Error
         {
             var timer = new Timer ();
-            GenericArray<Event> events = engine.get_events (event_ids);
+            var events = engine.get_events (event_ids);
             debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
-            return Events.to_variant (events);
+            return events;
         }
 
         public string[] find_related_uris (Variant time_range,
@@ -169,7 +169,7 @@
                 Events.from_variant (event_templates),
                 storage_state, num_events, result_type, sender);
             debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
-            return Events.to_variant (events);
+            return events;
         }
 
         public uint32[] insert_events (

_______________________________________________
Mailing list: https://launchpad.net/~zeitgeist
Post to     : zeitgeist@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zeitgeist
More help   : https://help.launchpad.net/ListHelp

Reply via email to