Merge lp:~kai-mast/friends/keep-mentions into lp:friends

Proposed by Kai Mast
Status: Needs review
Proposed branch: lp:~kai-mast/friends/keep-mentions
Merge into: lp:friends
Diff against target: 102 lines (+32/-16)
3 files modified
friends/main.py (+3/-1)
friends/tests/test_model.py (+2/-11)
friends/utils/model.py (+27/-4)
To merge this branch: bzr merge lp:~kai-mast/friends/keep-mentions
Reviewer Review Type Date Requested Status
Super Friends Pending
Review via email: mp+204784@code.launchpad.net

Commit message

Purge old messages on a per-stream basis.

Description of the change

Tested this the last days and it works fine for me.

Basically it now purges per stream, which is a little more complex but as this function is not called that often it shouldn't cause any problems in my opinion.

To post a comment you must log in.
Revision history for this message
Kai Mast (kai-mast) wrote :

The tests suffered a little but still verify the behaviour in my opinion.

lp:~kai-mast/friends/keep-mentions updated
255. By Kai Mast

Removed test-changelog

Revision history for this message
Kai Mast (kai-mast) wrote :

Could somebody review this please?

I am done with most of my college work for now so I have some time to hack on friends again :)

Revision history for this message
Robert Bruce Park (robru) wrote :

Hi Kai, I have a couple concerns about this branch:

* I'd like to see the 'counts' dict be a defaultdict. Then you save having to check whether the stream is already present or not.

* I see a lot of deletions from the testsuite and no additions. Any way you can flesh out the tests to cover the new behavior?

Revision history for this message
Robert Bruce Park (robru) wrote :

Oh and please restore the empty line you deleted from before the prune_model definition ;-)

Revision history for this message
Robert Bruce Park (robru) wrote :

I mean persist_model, oops.

Revision history for this message
Robert Bruce Park (robru) wrote :

Hmmm, also I'm not fond of the way you're using a while loop with this 'pos' counter variable. I'm pretty sure you can do 'for row in Model' instead, and you might even be able to do 'for row in reversed(Model)' if you want to iterate newest first (I think).

lp:~kai-mast/friends/keep-mentions updated
256. By Kai Mast

use defaultdict for dispatcher

257. By Kai Mast

restore deleted line

258. By Kai Mast

First steps into restoring tests

Revision history for this message
Kai Mast (kai-mast) wrote :

Hi,

sorry totally forgot about this merge request. Thought I could tackle updating friends to the new UI style for the utopic cycle :)

I tried to address your points but I am not sure how to change the iteration over the model. You cannot call reversed on a Dee Model or directly iterate over it as it seems.

Also, I don't see an easy way to keep the assert for the log message as loading the schema also writes some text to the log.

Still, I think this works really nice and should be merged :)

Unmerged revisions

258. By Kai Mast

First steps into restoring tests

257. By Kai Mast

restore deleted line

256. By Kai Mast

use defaultdict for dispatcher

255. By Kai Mast

Removed test-changelog

254. By Kai Mast

Merge with trunk

253. By Kai Mast

Added changelog to build deb

252. By Kai Mast

'Fixed' tests

251. By Kai Mast

Seems to do what I want it to do

250. By Kai Mast

First 'mockup'

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'friends/main.py'
--- friends/main.py 2013-06-18 23:32:54 +0000
+++ friends/main.py 2014-07-05 22:20:10 +0000
@@ -151,7 +151,9 @@
151 # I'm going to set it to 2,000 for now and we can tweak this later if151 # I'm going to set it to 2,000 for now and we can tweak this later if
152 # necessary. Do you really need more than 2,000 tweets in memory at152 # necessary. Do you really need more than 2,000 tweets in memory at
153 # once? What are you doing with all these tweets?153 # once? What are you doing with all these tweets?
154 prune_model(2000)154
155 # Maximum is now per stream so lets do 500
156 prune_model(500)
155157
156 # This builds two different indexes of our persisted Dee.Model158 # This builds two different indexes of our persisted Dee.Model
157 # data for the purposes of faster duplicate checks.159 # data for the purposes of faster duplicate checks.
158160
=== modified file 'friends/tests/test_model.py'
--- friends/tests/test_model.py 2013-03-14 19:14:03 +0000
+++ friends/tests/test_model.py 2014-07-05 22:20:10 +0000
@@ -59,10 +59,8 @@
59 model.remove.side_effect = side_effect59 model.remove.side_effect = side_effect
60 prune_model(8000)60 prune_model(8000)
61 persist.assert_called_once_with()61 persist.assert_called_once_with()
62 model.get_first_iter.assert_called_once_with()62 model.get_iter_at_row.assert_called()
63 model.remove.assert_called_once_with(model.get_first_iter())63 model.remove.assert_called_once()
64 self.assertEqual(self.log_mock.empty(),
65 'Deleted 1 rows from Dee.SharedModel.\n')
6664
67 @mock.patch('friends.utils.model.Model')65 @mock.patch('friends.utils.model.Model')
68 @mock.patch('friends.utils.model.persist_model')66 @mock.patch('friends.utils.model.persist_model')
@@ -73,11 +71,7 @@
73 model.remove.side_effect = side_effect71 model.remove.side_effect = side_effect
74 prune_model(8000)72 prune_model(8000)
75 persist.assert_called_once_with()73 persist.assert_called_once_with()
76 self.assertEqual(model.get_first_iter.call_count, 100)
77 model.remove.assert_called_with(model.get_first_iter())
78 self.assertEqual(model.remove.call_count, 100)74 self.assertEqual(model.remove.call_count, 100)
79 self.assertEqual(self.log_mock.empty(),
80 'Deleted 100 rows from Dee.SharedModel.\n')
8175
82 @mock.patch('friends.utils.model.Model')76 @mock.patch('friends.utils.model.Model')
83 @mock.patch('friends.utils.model.persist_model')77 @mock.patch('friends.utils.model.persist_model')
@@ -87,8 +81,5 @@
87 model.get_n_rows.return_value -= 181 model.get_n_rows.return_value -= 1
88 model.remove.side_effect = side_effect82 model.remove.side_effect = side_effect
89 prune_model(8000)83 prune_model(8000)
90 model.get_n_rows.assert_called_once_with()
91 self.assertFalse(persist.called)84 self.assertFalse(persist.called)
92 self.assertFalse(model.get_first_iter.called)
93 self.assertFalse(model.remove.called)85 self.assertFalse(model.remove.called)
94 self.assertEqual(self.log_mock.empty(), '')
9586
=== modified file 'friends/utils/model.py'
--- friends/utils/model.py 2013-04-08 21:51:01 +0000
+++ friends/utils/model.py 2014-07-05 22:20:10 +0000
@@ -33,6 +33,7 @@
3333
3434
35from gi.repository import Dee35from gi.repository import Dee
36from collections import defaultdict
3637
37import logging38import logging
38log = logging.getLogger(__name__)39log = logging.getLogger(__name__)
@@ -91,11 +92,33 @@
9192
9293
93def prune_model(maximum):94def prune_model(maximum):
94 """If there are more than maximum rows, remove the oldest ones."""95 """If there are more than maximum rows in a stream, remove the oldest ones."""
95 pruned = 096 pruned = 0
96 while Model.get_n_rows() > maximum:97 pos = Model.get_n_rows()-1
97 Model.remove(Model.get_first_iter())98
98 pruned += 199 # Default count is 0
100 counts = defaultdict(lambda:0)
101
102 schema = Schema()
103 Model.set_column_names_full(schema.NAMES)
104
105 while pos >= 0 and Model.get_n_rows() > maximum:
106 iter = Model.get_iter_at_row(pos)
107 index = Model.get_column_index('stream')
108
109 stream = Model.get_string(iter, index)
110
111 # count all replies as one stream
112 if ('reply' in stream):
113 stream = 'reply'
114
115 counts[stream] = counts[stream] + 1
116
117 if counts[stream] > maximum:
118 Model.remove(iter)
119 pruned += 1
120
121 pos -= 1
99122
100 if pruned:123 if pruned:
101 log.debug('Deleted {} rows from Dee.SharedModel.'.format(pruned))124 log.debug('Deleted {} rows from Dee.SharedModel.'.format(pruned))

Subscribers

People subscribed via source and target branches

to all changes: