Siegfried Gevatter has proposed merging lp:~rainct/zeitgeist/limit-dbus-mb into 
lp:zeitgeist.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)

For more details, see:
https://code.launchpad.net/~rainct/zeitgeist/limit-dbus-mb/+merge/99349
-- 
https://code.launchpad.net/~rainct/zeitgeist/limit-dbus-mb/+merge/99349
Your team Zeitgeist Framework Team is requested to review the proposed merge of 
lp:~rainct/zeitgeist/limit-dbus-mb into lp:zeitgeist.
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala	2012-03-20 12:19:23 +0000
+++ src/datamodel.vala	2012-03-26 15:10:24 +0000
@@ -621,6 +621,44 @@
             return vb.end ();
         }
 
+        public static Variant to_variant_with_limit (GenericArray<Event?> events)
+            throws EngineError
+        {
+            var vb = new VariantBuilder(new VariantType("a("+Utils.SIG_EVENT+")"));
+
+            size_t variant_size = 0;
+
+            for (int i = 0; i < events.length; ++i)
+            {
+                Variant event_variant;
+
+                if (events[i] != null)
+                {
+                    event_variant = events[i].to_variant ();
+                }
+                else
+                {
+                    event_variant = get_null_event_variant ();
+                }
+
+                variant_size += event_variant.get_size();
+                if (variant_size > Utils.MAX_DBUS_RESULT_SIZE)
+                {
+                    size_t avg_event_size = variant_size / (i+1);
+                    string error_message = ("Query exceeded size limit of % " +
+                        size_t.FORMAT + "MiB (roughly ~%d events).").printf (
+                            Utils.MAX_DBUS_RESULT_SIZE / 1024 / 1024,
+                            Utils.MAX_DBUS_RESULT_SIZE / avg_event_size);
+                    warning (error_message);
+                    throw new EngineError.TOO_MANY_RESULTS (error_message);
+                }
+
+                vb.add_value (event_variant);
+            }
+
+            return vb.end ();
+        }
+
         private static Variant get_null_event_variant ()
         {
             var vb = new VariantBuilder (new VariantType ("("+Utils.SIG_EVENT+")"));

=== modified file 'src/errors.vala'
--- src/errors.vala	2012-01-25 17:37:55 +0000
+++ src/errors.vala	2012-03-26 15:10:24 +0000
@@ -29,10 +29,11 @@
         DATABASE_CORRUPT,
         DATABASE_ERROR,
         DATABASE_RETIRE_FAILED,
+        EXISTING_INSTANCE,
         INVALID_ARGUMENT,
         INVALID_KEY,
-        EXISTING_INSTANCE,
         INVALID_SIGNATURE, // FIXME: change from EngineError to sth. + public
+        TOO_MANY_RESULTS,
     }
 
     // vala doesn't include proper headers, this fixes it

=== modified file 'src/utils.vala'
--- src/utils.vala	2012-03-01 14:47:30 +0000
+++ src/utils.vala	2012-03-26 15:10:24 +0000
@@ -38,6 +38,7 @@
         // D-Bus
         public const string DBUS_INTERFACE = "";
         public const string SIG_EVENT = "asaasay";
+        public const size_t MAX_DBUS_RESULT_SIZE = 4 * 1024 * 1024; // 4MiB
 
         // configure runtime cache for events
         // default size is 2000

=== modified file 'src/zeitgeist-daemon.vala'
--- src/zeitgeist-daemon.vala	2012-03-01 14:47:30 +0000
+++ src/zeitgeist-daemon.vala	2012-03-26 15:10:24 +0000
@@ -138,7 +138,7 @@
             var timer = new Timer ();
             GenericArray<Event> events = engine.get_events (event_ids);
             debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
-            return Events.to_variant (events);
+            return Events.to_variant_with_limit (events);
         }
 
         public string[] find_related_uris (Variant time_range,
@@ -176,7 +176,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.to_variant_with_limit (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