Merge authors: Seif Lotfy (seif) Related merge proposals: https://code.launchpad.net/~seif/zeitgeist/bb-extract-methods/+merge/80316 proposed by: Seif Lotfy (seif) ------------------------------------------------------------ revno: 323 [merge] committer: Siegfried-Angel Gevatter Pujals <siegfr...@gevatter.com> branch nick: bluebird timestamp: Sat 2011-10-29 12:48:26 +0200 message: Merge Seif's lp:~seif/zeitgeist/bb-extract-methods: Extract event and subj generation out of get_events into get_event_from_row and get_subject_from_row. modified: src/engine.vala
-- lp:~zeitgeist/zeitgeist/bluebird https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird Your team Zeitgeist Framework Team is subscribed to branch lp:~zeitgeist/zeitgeist/bluebird. To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'src/engine.vala' --- src/engine.vala 2011-10-20 11:20:36 +0000 +++ src/engine.vala 2011-10-29 10:48:26 +0000 @@ -67,6 +67,50 @@ return extension_collection.get_extension_names (); } + private Event get_event_from_row (Sqlite.Statement stmt, uint32 event_id) + { + Event 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); + } + return event; + } + + private Subject get_subject_from_row (Sqlite.Statement stmt) + { + 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)); + return subject; + } + public GenericArray<Event?> get_events(uint32[] event_ids, BusName? sender=null) throws EngineError { @@ -76,66 +120,32 @@ // 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?> (); + 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); + Sqlite.Statement stmt; + int 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); + // Create Events and Subjects from rows while ((rc = stmt.step ()) == Sqlite.ROW) { uint32 event_id = (uint32) stmt.column_int64 (EventViewRows.ID); Event? 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 - 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); - } + event = get_event_from_row(stmt, event_id); 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)); - + Subject subject = get_subject_from_row(stmt); event.add_subject(subject); } if (rc != Sqlite.DONE) @@ -144,6 +154,7 @@ rc, db.errmsg ()); } + // Sort events according to the sequence of event_ids var results = new GenericArray<Event?> (); results.length = event_ids.length; int i = 0;
_______________________________________________ Mailing list: https://launchpad.net/~zeitgeist Post to : zeitgeist@lists.launchpad.net Unsubscribe : https://launchpad.net/~zeitgeist More help : https://help.launchpad.net/ListHelp