zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #04280
[Merge] lp:~j-bitron/zeitgeist/bb-memory into lp:~zeitgeist/zeitgeist/bluebird
Seif Lotfy has proposed merging lp:~j-bitron/zeitgeist/bb-memory into lp:~zeitgeist/zeitgeist/bluebird.
Requested reviews:
Zeitgeist Framework Team (zeitgeist)
For more details, see:
https://code.launchpad.net/~j-bitron/zeitgeist/bb-memory/+merge/79776
Juerg's attempt to reduce fragmentation
the branch results in usage of 75MB instead of 114MB with the cost of 1s slowdown for a reqeust of 50k events
--
https://code.launchpad.net/~j-bitron/zeitgeist/bb-memory/+merge/79776
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~j-bitron/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 08:42:59 +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 08:42:59 +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
@@ -80,81 +80,95 @@
int rc;
if (event_ids.length == 0)
- return new GenericArray<Event?> ();
- var sql_event_ids = database.get_sql_string_from_event_ids (event_ids);
+ return new Variant.array (null, null);
string sql = """
SELECT * FROM event_view
- WHERE id IN (%s)
- """.printf (sql_event_ids);
+ WHERE id = ?
+ """;
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 VariantBuilder (new VariantType ("a("+Utils.SIG_EVENT+")"));
- while ((rc = stmt.step ()) == Sqlite.ROW)
+ foreach (var event_id in event_ids)
{
- uint32 event_id = (uint32) stmt.column_int64 (EventViewRows.ID);
- Event? event = events.lookup (event_id);
- if (event == null)
+ stmt.bind_int64 (1, event_id);
+
+ Event? event = null;
+
+ while ((rc = stmt.step ()) == Sqlite.ROW)
{
- 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)
+ if (event == null)
{
- event.payload = new ByteArray();
- event.payload.append(data);
+ 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);
+ }
}
- 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);
- }
- 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 event_ids)
- {
- results.set(i++, events.lookup (id));
- }
-
- extension_collection.call_post_get_events (results, sender);
-
- return results;
+
+ 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);
+ }
+ if (rc != Sqlite.DONE)
+ {
+ throw new EngineError.DATABASE_ERROR ("Error: %d, %s\n",
+ rc, db.errmsg ());
+ }
+
+ // statement may get reused in next iteration, make sure it's reset
+ rc = stmt.reset ();
+ if (rc != Sqlite.OK)
+ {
+ throw new EngineError.DATABASE_ERROR ("Error: %d, %s\n",
+ rc, db.errmsg ());
+ }
+
+ if (event != null)
+ {
+ events.add_value (event.to_variant ());
+ }
+ else
+ {
+ events.add_value (Events.get_null_event_variant ());
+ }
+ }
+
+ Variant v = events.end ();
+
+ extension_collection.call_post_get_events (v, sender);
+
+ return v;
}
public uint32[] find_event_ids (TimeRange time_range,
@@ -344,7 +358,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 08:42:59 +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 08:42:59 +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 08:42:59 +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 (
Follow ups