GTG

Merge lp:~bertrand-rousseau/gtg/bugfix-984880-tag-relation-not-stored into lp:~gtg/gtg/old-trunk

Proposed by Bertrand Rousseau
Status: Rejected
Rejected by: Izidor Matušov
Proposed branch: lp:~bertrand-rousseau/gtg/bugfix-984880-tag-relation-not-stored
Merge into: lp:~gtg/gtg/old-trunk
Diff against target: 62 lines (+25/-2)
2 files modified
GTG/core/datastore.py (+25/-0)
GTG/core/tag.py (+0/-2)
To merge this branch: bzr merge lp:~bertrand-rousseau/gtg/bugfix-984880-tag-relation-not-stored
Reviewer Review Type Date Requested Status
Gtg developers Pending
Review via email: mp+120290@code.launchpad.net

Description of the change

Here's a patch that introduces tag tree modifications monitoring from the datastore. This allows to request a save of the tag tree each time a tag is modified. However, in order to reduce the number of save requests, a timeout is added to only request a save 1 second after a node-modified signal is received. That behavior allows to filter unnecessary saves when a burst of "node-modified" signals are sent.

The good part:
 - it fixes bug #984880 (tag relations not saved on kill)
 - tag tree will now be regularly be saved when tags are modified (in the generic sense), which is the feature we want.

The bad part:
 - tag's "node-modified" signals are often sent unnecessarily (this is not related to this patch, it's a consequence of GTG current implementation). For instance, when a task is modified, it always notifies _all_ its tags as modified although most of the times, they are not (it serves as a hack to request a refresh of the tag list counters I suppose). With this patch, this behavior will cause a tag save request to be sent unnecessarily at each task modification. Not cool: performing unnecessary work always increase the risk of errors. We should figure out a way to reduce/remove those requests or to filter them out of the monitoring. No idea so far on how to do this, but I haven't though much about it too.
 - this patch changes the way tags are saved when tag attributes are edited. Before, a save was explicitly requested. Now, it catches the "node-modified" signal, so it happens a bit more indirectly. It may cause side-effects, which will require some testing to figure out.
 - obviously, if GTG is killed before 1 second after a tag is modified, the tag tree won't be updated on the disk. But now, if it does, it's more probably due to a code-related crash rather than a user-related action (indeed, killing GTG explicitly in less than 1 second after having modified a tag is really hard for a user), so we can't guarantee a safe tag tree save anyway.

Release-wise, I think this patch needs to be discussed further, and is too "experimental" to land in 0.3. But I'm interested in discussing options here so I start a merge request anyway.

To post a comment you must log in.
Revision history for this message
Izidor Matušov (izidor) wrote :

After discussion at the mailing list, closing this merge request as "rejected". We should fix this properly soon.

Unmerged revisions

1229. By Bertrand Rousseau

lint and pep8

1228. By Bertrand Rousseau

Register a callback on 'node-modified' signal for tag: allows to watch for tag modifications and request a tag tree save. Also, remove the explicit save request on tag attribute change since those can be catched by monitoring tag modifications anyway.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'GTG/core/datastore.py'
2--- GTG/core/datastore.py 2012-08-12 22:32:09 +0000
3+++ GTG/core/datastore.py 2012-08-19 12:50:45 +0000
4@@ -28,6 +28,7 @@
5 import threading
6 import uuid
7 import os.path
8+import gobject
9 from collections import deque
10
11 from GTG.core import requester
12@@ -75,6 +76,10 @@
13 self._activate_non_default_backends)
14 self.filtered_datastore = FilteredDataStore(self)
15 self._backend_mutex = threading.Lock()
16+ # Monitor tag tree modifications
17+ self.tag_mods_watch_id = None
18+ self.__tagstore.get_main_view().register_cllbck('node-modified', \
19+ self.on_tag_modified)
20
21 ##########################################################################
22 ### Helper functions (get_ methods for Datastore embedded objects)
23@@ -271,6 +276,26 @@
24
25 cleanxml.savexml(self.tagfile, doc, backup=True)
26
27+ def on_tag_modified(self, tid, path=None): # pylint: disable-msg=W0613
28+ """Callback: when a tag is modified, we save the tag tree."""
29+ # ignore modifications on pseudo-tags
30+ if tid == "gtg-tags-all" or \
31+ tid == "gtg-tags-none":
32+ return
33+ # else, we must save the tag tree
34+ def __tag_mods_request_save(self):
35+ """ Request a tag tree save and unregister the watcher."""
36+ self.tag_mods_watch_id = None
37+ self.save_tagtree()
38+ return False
39+ # filter out change requests to reduce unnecessary saves
40+ if self.tag_mods_watch_id is None:
41+ # There is no watchers for tag modifications. Register one.
42+ # We then wait 1 second before saving the tag tree in order to
43+ # reduce saves
44+ self.tag_mods_watch_id = gobject.timeout_add(1000, \
45+ __tag_mods_request_save, self)
46+
47 ##########################################################################
48 ### Tasks functions
49 ##########################################################################
50
51=== modified file 'GTG/core/tag.py'
52--- GTG/core/tag.py 2012-07-23 14:43:13 +0000
53+++ GTG/core/tag.py 2012-08-19 12:50:45 +0000
54@@ -95,8 +95,6 @@
55 # Attributes should all be strings.
56 val = unicode(str(att_value), "UTF-8")
57 self._attributes[att_name] = val
58- if self._save:
59- self._save()
60 modified = True
61 if modified:
62 self.modified()

Subscribers

People subscribed via source and target branches

to status/vote changes: