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
1=== modified file 'src/datamodel.vala'
2--- src/datamodel.vala 2012-03-20 12:19:23 +0000
3+++ src/datamodel.vala 2012-03-26 15:34:19 +0000
4@@ -621,6 +621,46 @@
5 return vb.end ();
6 }
7
8+ /* Same as to_variant but raises an exception if the variant size
9+ * exceeds `limit' bytes.
10+ * */
11+ public static Variant to_variant_with_limit (GenericArray<Event?> events,
12+ size_t limit=Utils.MAX_DBUS_RESULT_SIZE) throws EngineError
13+ {
14+ var vb = new VariantBuilder(new VariantType("a("+Utils.SIG_EVENT+")"));
15+
16+ size_t variant_size = 0;
17+
18+ for (int i = 0; i < events.length; ++i)
19+ {
20+ Variant event_variant;
21+
22+ if (events[i] != null)
23+ {
24+ event_variant = events[i].to_variant ();
25+ }
26+ else
27+ {
28+ event_variant = get_null_event_variant ();
29+ }
30+
31+ variant_size += event_variant.get_size();
32+ if (variant_size > limit)
33+ {
34+ size_t avg_event_size = variant_size / (i+1);
35+ string error_message = ("Query exceeded size limit of % " +
36+ size_t.FORMAT + "MiB (roughly ~%d events).").printf (
37+ limit / 1024 / 1024, limit / avg_event_size);
38+ warning (error_message);
39+ throw new EngineError.TOO_MANY_RESULTS (error_message);
40+ }
41+
42+ vb.add_value (event_variant);
43+ }
44+
45+ return vb.end ();
46+ }
47+
48 private static Variant get_null_event_variant ()
49 {
50 var vb = new VariantBuilder (new VariantType ("("+Utils.SIG_EVENT+")"));
51
52=== modified file 'src/errors.vala'
53--- src/errors.vala 2012-01-25 17:37:55 +0000
54+++ src/errors.vala 2012-03-26 15:34:19 +0000
55@@ -29,10 +29,11 @@
56 DATABASE_CORRUPT,
57 DATABASE_ERROR,
58 DATABASE_RETIRE_FAILED,
59+ EXISTING_INSTANCE,
60 INVALID_ARGUMENT,
61 INVALID_KEY,
62- EXISTING_INSTANCE,
63 INVALID_SIGNATURE, // FIXME: change from EngineError to sth. + public
64+ TOO_MANY_RESULTS,
65 }
66
67 // vala doesn't include proper headers, this fixes it
68
69=== modified file 'src/utils.vala'
70--- src/utils.vala 2012-03-01 14:47:30 +0000
71+++ src/utils.vala 2012-03-26 15:34:19 +0000
72@@ -38,6 +38,7 @@
73 // D-Bus
74 public const string DBUS_INTERFACE = "";
75 public const string SIG_EVENT = "asaasay";
76+ public const size_t MAX_DBUS_RESULT_SIZE = 4 * 1024 * 1024; // 4MiB
77
78 // configure runtime cache for events
79 // default size is 2000
80
81=== modified file 'src/zeitgeist-daemon.vala'
82--- src/zeitgeist-daemon.vala 2012-03-01 14:47:30 +0000
83+++ src/zeitgeist-daemon.vala 2012-03-26 15:34:19 +0000
84@@ -138,7 +138,7 @@
85 var timer = new Timer ();
86 GenericArray<Event> events = engine.get_events (event_ids);
87 debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
88- return Events.to_variant (events);
89+ return Events.to_variant_with_limit (events);
90 }
91
92 public string[] find_related_uris (Variant time_range,
93@@ -176,7 +176,7 @@
94 Events.from_variant (event_templates),
95 storage_state, num_events, result_type, sender);
96 debug ("%s executed in %f seconds", Log.METHOD, timer.elapsed ());
97- return Events.to_variant (events);
98+ return Events.to_variant_with_limit (events);
99 }
100
101 public uint32[] insert_events (

Subscribers

People subscribed via source and target branches