Merge lp:~rainct/zeitgeist/limit-dbus-mb into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Merged
Approved by: Michal Hruby
Approved revision: 451
Merged at revision: 452
Proposed branch: lp:~rainct/zeitgeist/limit-dbus-mb
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 101 lines (+45/-3)
4 files modified
src/datamodel.vala (+40/-0)
src/errors.vala (+2/-1)
src/utils.vala (+1/-0)
src/zeitgeist-daemon.vala (+2/-2)
To merge this branch: bzr merge lp:~rainct/zeitgeist/limit-dbus-mb
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+99349@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Can we turn this into:

public static Variant to_variant_with_limit (GenericArray<Event?> events)
->
public static Variant to_variant_with_limit (GenericArray<Event?> events, size_t limit = Utils.MAX_DBUS_RESULT_SIZE)

review: Needs Fixing
lp:~rainct/zeitgeist/limit-dbus-mb updated
451. By Siegfried Gevatter

Add limit parameter to Events.to_variant_with_limit

Revision history for this message
Michal Hruby (mhr3) wrote :

Great!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/datamodel.vala'
--- src/datamodel.vala 2012-03-20 12:19:23 +0000
+++ src/datamodel.vala 2012-03-26 15:34:19 +0000
@@ -621,6 +621,46 @@
621 return vb.end ();621 return vb.end ();
622 }622 }
623623
624 /* Same as to_variant but raises an exception if the variant size
625 * exceeds `limit' bytes.
626 * */
627 public static Variant to_variant_with_limit (GenericArray<Event?> events,
628 size_t limit=Utils.MAX_DBUS_RESULT_SIZE) throws EngineError
629 {
630 var vb = new VariantBuilder(new VariantType("a("+Utils.SIG_EVENT+")"));
631
632 size_t variant_size = 0;
633
634 for (int i = 0; i < events.length; ++i)
635 {
636 Variant event_variant;
637
638 if (events[i] != null)
639 {
640 event_variant = events[i].to_variant ();
641 }
642 else
643 {
644 event_variant = get_null_event_variant ();
645 }
646
647 variant_size += event_variant.get_size();
648 if (variant_size > limit)
649 {
650 size_t avg_event_size = variant_size / (i+1);
651 string error_message = ("Query exceeded size limit of % " +
652 size_t.FORMAT + "MiB (roughly ~%d events).").printf (
653 limit / 1024 / 1024, limit / avg_event_size);
654 warning (error_message);
655 throw new EngineError.TOO_MANY_RESULTS (error_message);
656 }
657
658 vb.add_value (event_variant);
659 }
660
661 return vb.end ();
662 }
663
624 private static Variant get_null_event_variant ()664 private static Variant get_null_event_variant ()
625 {665 {
626 var vb = new VariantBuilder (new VariantType ("("+Utils.SIG_EVENT+")"));666 var vb = new VariantBuilder (new VariantType ("("+Utils.SIG_EVENT+")"));
627667
=== modified file 'src/errors.vala'
--- src/errors.vala 2012-01-25 17:37:55 +0000
+++ src/errors.vala 2012-03-26 15:34:19 +0000
@@ -29,10 +29,11 @@
29 DATABASE_CORRUPT,29 DATABASE_CORRUPT,
30 DATABASE_ERROR,30 DATABASE_ERROR,
31 DATABASE_RETIRE_FAILED,31 DATABASE_RETIRE_FAILED,
32 EXISTING_INSTANCE,
32 INVALID_ARGUMENT,33 INVALID_ARGUMENT,
33 INVALID_KEY,34 INVALID_KEY,
34 EXISTING_INSTANCE,
35 INVALID_SIGNATURE, // FIXME: change from EngineError to sth. + public35 INVALID_SIGNATURE, // FIXME: change from EngineError to sth. + public
36 TOO_MANY_RESULTS,
36 }37 }
3738
38 // vala doesn't include proper headers, this fixes it39 // vala doesn't include proper headers, this fixes it
3940
=== modified file 'src/utils.vala'
--- src/utils.vala 2012-03-01 14:47:30 +0000
+++ src/utils.vala 2012-03-26 15:34:19 +0000
@@ -38,6 +38,7 @@
38 // D-Bus38 // D-Bus
39 public const string DBUS_INTERFACE = "";39 public const string DBUS_INTERFACE = "";
40 public const string SIG_EVENT = "asaasay";40 public const string SIG_EVENT = "asaasay";
41 public const size_t MAX_DBUS_RESULT_SIZE = 4 * 1024 * 1024; // 4MiB
4142
42 // configure runtime cache for events43 // configure runtime cache for events
43 // default size is 200044 // default size is 2000
4445
=== 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:34:19 +0000
@@ -138,7 +138,7 @@
138 var timer = new Timer ();138 var timer = new Timer ();
139 GenericArray<Event> events = engine.get_events (event_ids);139 GenericArray<Event> events = engine.get_events (event_ids);
140 debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());140 debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
141 return Events.to_variant (events);141 return Events.to_variant_with_limit (events);
142 }142 }
143143
144 public string[] find_related_uris (Variant time_range,144 public string[] find_related_uris (Variant time_range,
@@ -176,7 +176,7 @@
176 Events.from_variant (event_templates),176 Events.from_variant (event_templates),
177 storage_state, num_events, result_type, sender);177 storage_state, num_events, result_type, sender);
178 debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());178 debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
179 return Events.to_variant (events);179 return Events.to_variant_with_limit (events);
180 }180 }
181181
182 public uint32[] insert_events (182 public uint32[] insert_events (

Subscribers

People subscribed via source and target branches