Merge lp:~tiagosh/history-service/fix-unreadCount-trigger into lp:history-service

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 160
Merged at revision: 159
Proposed branch: lp:~tiagosh/history-service/fix-unreadCount-trigger
Merge into: lp:history-service
Diff against target: 141 lines (+137/-0)
1 file modified
plugins/sqlite/schema/v8.sql (+137/-0)
To merge this branch: bzr merge lp:~tiagosh/history-service/fix-unreadCount-trigger
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Gustavo Pichorim Boiko (community) Approve
Review via email: mp+228742@code.launchpad.net

Commit message

Fix unreadCount update.

Description of the change

Fix unreadCount update.

--Checklist--

Are there any related MPs required for this MP to build/function as expected? Please list.
No

Is your branch in sync with latest trunk (e.g. bzr pull lp:trunk -> no changes)
Yes

Did you perform an exploratory manual test run of your code change and any related functionality on device or emulator?
Yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/history-service) on device or emulator?
Yes

If you changed the UI, was the change specified/approved by design?
N/A

If you changed the packaging (debian), did you add a core-dev as a reviewer to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

It would be nice to also add to v8.sql some UPDATE queries to update the existing data, otherwise it will only be updated when new events arrive.

review: Needs Fixing
160. By Tiago Salem Herrmann

also update voice events

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
Yes

Did CI run pass? If not, please explain why.
Yes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
Yes

After discussing more with Tiago, we came to the conclusion it is not worth writing queries to update the unread count on existing entries as they are not simple queries and we risk breaking existing installations, so the counters will only be updated after new events arrive on each thread.
Code looks good and works as expected!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'plugins/sqlite/schema/v8.sql'
2--- plugins/sqlite/schema/v8.sql 1970-01-01 00:00:00 +0000
3+++ plugins/sqlite/schema/v8.sql 2014-07-30 16:39:22 +0000
4@@ -0,0 +1,137 @@
5+DROP TRIGGER text_events_insert_trigger;
6+DROP TRIGGER text_events_update_trigger;
7+DROP TRIGGER text_events_delete_trigger;
8+DROP TRIGGER voice_events_insert_trigger;
9+DROP TRIGGER voice_events_update_trigger;
10+DROP TRIGGER voice_events_delete_trigger;
11+
12+CREATE TRIGGER text_events_insert_trigger AFTER INSERT ON text_events
13+FOR EACH ROW
14+BEGIN
15+ UPDATE threads SET count=(SELECT count(eventId) FROM text_events WHERE
16+ accountId=new.accountId AND
17+ threadId=new.threadId)
18+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=0;
19+ UPDATE threads SET unreadCount=(SELECT count(eventId) FROM text_events WHERE
20+ accountId=new.accountId AND threadId=new.threadId AND newEvent='1')
21+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=0;
22+ UPDATE threads SET lastEventId=(SELECT eventId FROM text_events WHERE
23+ accountId=new.accountId AND
24+ threadId=new.threadId
25+ ORDER BY timestamp DESC LIMIT 1)
26+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=0;
27+ UPDATE threads SET lastEventTimestamp=(SELECT timestamp FROM text_events WHERE
28+ accountId=new.accountId AND
29+ threadId=new.threadId
30+ ORDER BY timestamp DESC LIMIT 1)
31+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=0;
32+END;
33+CREATE TRIGGER text_events_update_trigger AFTER UPDATE ON text_events
34+FOR EACH ROW
35+BEGIN
36+ UPDATE threads SET count=(SELECT count(eventId) FROM text_events WHERE
37+ accountId=new.accountId AND
38+ threadId=new.threadId)
39+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=0;
40+ UPDATE threads SET unreadCount=(SELECT count(eventId) FROM text_events WHERE
41+ accountId=new.accountId AND threadId=new.threadId AND newEvent='1')
42+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=0;
43+ UPDATE threads SET lastEventId=(SELECT eventId FROM text_events WHERE
44+ accountId=new.accountId AND
45+ threadId=new.threadId
46+ ORDER BY timestamp DESC LIMIT 1)
47+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=0;
48+ UPDATE threads SET lastEventTimestamp=(SELECT timestamp FROM text_events WHERE
49+ accountId=new.accountId AND
50+ threadId=new.threadId
51+ ORDER BY timestamp DESC LIMIT 1)
52+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=0;
53+END;
54+CREATE TRIGGER text_events_delete_trigger AFTER DELETE ON text_events
55+FOR EACH ROW
56+BEGIN
57+ UPDATE threads SET count=(SELECT count(eventId) FROM text_events WHERE
58+ accountId=old.accountId AND
59+ threadId=old.threadId)
60+ WHERE accountId=old.accountId AND threadId=old.threadId AND type=0;
61+ UPDATE threads SET unreadCount=(SELECT count(eventId) FROM text_events WHERE
62+ accountId=old.accountId AND threadId=old.threadId AND newEvent='1')
63+ WHERE accountId=old.accountId AND threadId=old.threadId AND type=0;
64+ UPDATE threads SET lastEventId=(SELECT eventId FROM text_events WHERE
65+ accountId=old.accountId AND
66+ threadId=old.threadId
67+ ORDER BY timestamp DESC LIMIT 1)
68+ WHERE accountId=old.accountId AND threadId=old.threadId AND type=0;
69+ UPDATE threads SET lastEventTimestamp=(SELECT timestamp FROM text_events WHERE
70+ accountId=old.accountId AND
71+ threadId=old.threadId
72+ ORDER BY timestamp DESC LIMIT 1)
73+ WHERE accountId=old.accountId AND threadId=old.threadId AND type=0;
74+ DELETE from text_event_attachments WHERE
75+ accountId=old.accountId AND
76+ threadId=old.threadId AND
77+ eventId=old.eventId;
78+END;
79+CREATE TRIGGER voice_events_insert_trigger AFTER INSERT ON voice_events
80+FOR EACH ROW
81+BEGIN
82+ UPDATE threads SET count=(SELECT count(eventId) FROM voice_events WHERE
83+ accountId=new.accountId AND
84+ threadId=new.threadId)
85+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=1;
86+ UPDATE threads SET unreadCount=(SELECT count(eventId) FROM voice_events WHERE
87+ accountId=new.accountId AND threadId=new.threadId AND newEvent='1')
88+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=1;
89+ UPDATE threads SET lastEventId=(SELECT eventId FROM voice_events WHERE
90+ accountId=new.accountId AND
91+ threadId=new.threadId
92+ ORDER BY timestamp DESC LIMIT 1)
93+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=1;
94+ UPDATE threads SET lastEventTimestamp=(SELECT timestamp FROM voice_events WHERE
95+ accountId=new.accountId AND
96+ threadId=new.threadId
97+ ORDER BY timestamp DESC LIMIT 1)
98+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=1;
99+END;
100+CREATE TRIGGER voice_events_update_trigger AFTER UPDATE ON voice_events
101+FOR EACH ROW
102+BEGIN
103+ UPDATE threads SET count=(SELECT count(eventId) FROM voice_events WHERE
104+ accountId=new.accountId AND
105+ threadId=new.threadId)
106+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=1;
107+ UPDATE threads SET unreadCount=(SELECT count(eventId) FROM voice_events WHERE
108+ accountId=new.accountId AND threadId=new.threadId AND newEvent='1')
109+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=1;
110+ UPDATE threads SET lastEventId=(SELECT eventId FROM voice_events WHERE
111+ accountId=new.accountId AND
112+ threadId=new.threadId
113+ ORDER BY timestamp DESC LIMIT 1)
114+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=1;
115+ UPDATE threads SET lastEventTimestamp=(SELECT timestamp FROM voice_events WHERE
116+ accountId=new.accountId AND
117+ threadId=new.threadId
118+ ORDER BY timestamp DESC LIMIT 1)
119+ WHERE accountId=new.accountId AND threadId=new.threadId AND type=1;
120+END;
121+CREATE TRIGGER voice_events_delete_trigger AFTER DELETE ON voice_events
122+FOR EACH ROW
123+BEGIN
124+ UPDATE threads SET count=(SELECT count(eventId) FROM voice_events WHERE
125+ accountId=old.accountId AND
126+ threadId=old.threadId)
127+ WHERE accountId=old.accountId AND threadId=old.threadId AND type=1;
128+ UPDATE threads SET unreadCount=(SELECT count(eventId) FROM voice_events WHERE
129+ accountId=old.accountId AND threadId=old.threadId AND newEvent='1')
130+ WHERE accountId=old.accountId AND threadId=old.threadId AND type=1;
131+ UPDATE threads SET lastEventId=(SELECT eventId FROM voice_events WHERE
132+ accountId=old.accountId AND
133+ threadId=old.threadId
134+ ORDER BY timestamp DESC LIMIT 1)
135+ WHERE accountId=old.accountId AND threadId=old.threadId AND type=1;
136+ UPDATE threads SET lastEventTimestamp=(SELECT timestamp FROM voice_events WHERE
137+ accountId=old.accountId AND
138+ threadId=old.threadId
139+ ORDER BY timestamp DESC LIMIT 1)
140+ WHERE accountId=old.accountId AND threadId=old.threadId AND type=1;
141+END;

Subscribers

People subscribed via source and target branches