View Single Post
Posts: 249 | Thanked: 277 times | Joined on May 2010 @ Brighton, UK
#13
I've been doing a lot of work with the conversations database as I've been working on a event importer/exporter for the last few months on and off.

1st, the code you linked to is an old version. I put up the current version here: https://gitorious.org/rtcom-eventlog...om-eventlogger

2nd, I encountered a problem when making changes to the database when the event count > ~2500. Basically, the triggers for keeping the group cache up to date seems to be horribly inefficient and would block for several seconds for each event. This isn't a problem when you send a SMS or make a phone call several minutes apart at best, but when bulk loading content or in a quick SMS conversation it might break. Anyway, here's the culprits:
PHP Code:
CREATE TRIGGER gc_update_ev_add1 BEFORE INSERT ON Events FOR EACH ROW WHEN NEW.group_uid IS NOT NULL BEGIN INSERT OR IGNORE INTO GroupCache (event_idservice_idgroup_uidtotal_eventsread_eventsflagsVALUES (0, NEW.service_id, NEW.group_uid000); END;
CREATE TRIGGER gc_update_ev_add4 AFTER INSERT ON Events FOR EACH ROW WHEN NEW.group_uid IS NOT NULL BEGIN UPDATE GroupCache SET event_id = NEW.idtotal_events total_events 1read_events read_events + NEW.is_readflags flags | NEW.flags WHERE group_uid = NEW.group_uidEND;
CREATE TRIGGER gc_update_ev_update AFTER UPDATE ON Events FOR EACH ROW WHEN NEW.group_uid IS NOT NULL BEGIN UPDATE GroupCache SET read_events read_events OLD.is_read + NEW.is_readflags = (flags & (~OLD.flags)) | NEW.flags WHERE group_uid = NEW.group_uidEND
In my utility I disable the triggers and achieve the same effect with some code afterwards:
PHP Code:
    const char sqlUpdateGroupCache(
        
"INSERT OR REPLACE INTO groupcache "
        "SELECT id, service_id, group_uid, total, readcount, mergedflags "
        "FROM events e, "
            "(SELECT max(start_time) as maxdate, group_uid as maxgid, count(group_uid) as total, total(is_read) as readcount, _OR(flags) as mergedflags "
            "FROM events "
            "GROUP BY maxgid) maxresults "
        "WHERE group_uid = maxgid AND start_time=maxresults.maxdate "
        "GROUP BY group_uid"
); 
It runs just the once, updates everything, and is quick. If I ever get around to rewriting the conversations UI, I'll try dumping the triggers and just have that code execute when the conversations opens.

...though admittedly, you can't use that from the command line as the flags require a custom function '_OR()' in order to be able to Or the flag values together (not sure why it even does that TBH...but I have to do it just in case...)

...anyway...try disabling the triggers and see if it resolves your problem, and if so...try to come up with a way to update the cache another way :/
 

The Following 2 Users Say Thank You to mr_jrt For This Useful Post: