~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/bugs/doc/checkwatches-batching.txt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-22 04:55:30 UTC
  • mfrom: (14577.1.1 testfix)
  • Revision ID: launchpad@pqm.canonical.com-20111222045530-wki9iu6c0ysqqwkx
[r=wgrant][no-qa] Fix test_publisherconfig lpstorm import. Probably a
        silent conflict between megalint and apocalypse.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Batching in checkwatches
 
2
========================
 
3
 
 
4
The checkwatches system tries to be sensitive to batching options
 
5
given. Specifically, the _getRemoteIdsToCheck() method is responsible
 
6
for batching up operations.
 
7
 
 
8
    >>> import transaction
 
9
    >>> from lp.bugs.scripts.checkwatches import CheckwatchesMaster
 
10
    >>> from pprint import pprint
 
11
 
 
12
    >>> updater = CheckwatchesMaster(transaction)
 
13
    >>> transaction.commit()
 
14
 
 
15
 
 
16
Basics
 
17
------
 
18
 
 
19
    >>> class BasicRemoteSystem:
 
20
    ...     sync_comments = False
 
21
 
 
22
    >>> remote = BasicRemoteSystem()
 
23
 
 
24
When there are no bug watches to check, the result is empty.
 
25
 
 
26
    >>> pprint(updater._getRemoteIdsToCheck(
 
27
    ...     remote, [], batch_size=2))
 
28
    {'all_remote_ids': [],
 
29
     'remote_ids_to_check': [],
 
30
     'unmodified_remote_ids': []}
 
31
 
 
32
With up to batch_size watches, it advises us to check all the remote
 
33
bug IDs given.
 
34
 
 
35
    >>> bug_watches = [
 
36
    ...     factory.makeBugWatch(remote_bug='a'),
 
37
    ...     factory.makeBugWatch(remote_bug='b'),
 
38
    ...     ]
 
39
    >>> transaction.commit()
 
40
 
 
41
    >>> pprint(updater._getRemoteIdsToCheck(
 
42
    ...     remote, bug_watches, batch_size=2))
 
43
    {'all_remote_ids': [u'a', u'b'],
 
44
     'remote_ids_to_check': [u'a', u'b'],
 
45
     'unmodified_remote_ids': []}
 
46
 
 
47
With more than batch_size watches, it advises to only check a subset
 
48
of the remote bug IDs given.
 
49
 
 
50
    >>> bug_watches = [
 
51
    ...     factory.makeBugWatch(remote_bug='a'),
 
52
    ...     factory.makeBugWatch(remote_bug='b'),
 
53
    ...     factory.makeBugWatch(remote_bug='c'),
 
54
    ...     ]
 
55
    >>> transaction.commit()
 
56
 
 
57
    >>> pprint(updater._getRemoteIdsToCheck(
 
58
    ...     remote, bug_watches, batch_size=2))
 
59
    {'all_remote_ids': [u'a', u'b'],
 
60
     'remote_ids_to_check': [u'a', u'b'],
 
61
     'unmodified_remote_ids': []}
 
62
 
 
63
 
 
64
Querying the remote system for modified bugs
 
65
--------------------------------------------
 
66
 
 
67
For bug watches that have been checked before, the remote system is
 
68
asked which of a list of bugs have been modified since a given date.
 
69
 
 
70
    >>> from zope.security.proxy import removeSecurityProxy
 
71
    >>> from datetime import datetime
 
72
    >>> from pytz import UTC
 
73
 
 
74
    >>> class QueryableRemoteSystem:
 
75
    ...     sync_comments = False
 
76
    ...     def getModifiedRemoteBugs(self, remote_bug_ids, timestamp):
 
77
    ...         print "getModifiedRemoteBugs(%r, %r)" % (
 
78
    ...             remote_bug_ids, timestamp)
 
79
    ...         # Return every *other* bug ID for demo purposes.
 
80
    ...         return remote_bug_ids[::2]
 
81
 
 
82
    >>> remote = QueryableRemoteSystem()
 
83
    >>> now = datetime(2010, 01, 13, 16, 52, tzinfo=UTC)
 
84
 
 
85
When there are no bug watches to check, the result is empty, and the
 
86
remote system is not queried.
 
87
 
 
88
    >>> ids_to_check = updater._getRemoteIdsToCheck(
 
89
    ...     remote, [], batch_size=2,
 
90
    ...     server_time=now, now=now)
 
91
 
 
92
    >>> pprint(ids_to_check)
 
93
    {'all_remote_ids': [],
 
94
     'remote_ids_to_check': [],
 
95
     'unmodified_remote_ids': []}
 
96
 
 
97
With up to batch_size previously checked watches, the remote system is
 
98
queried once, and we are advised to check only one of the watches.
 
99
 
 
100
    >>> bug_watches = [
 
101
    ...     factory.makeBugWatch(remote_bug='a'),
 
102
    ...     factory.makeBugWatch(remote_bug='b'),
 
103
    ...     ]
 
104
    >>> for bug_watch in bug_watches:
 
105
    ...     removeSecurityProxy(bug_watch).lastchecked = now
 
106
    >>> transaction.commit()
 
107
 
 
108
    >>> ids_to_check = updater._getRemoteIdsToCheck(
 
109
    ...     remote, bug_watches, batch_size=2,
 
110
    ...     server_time=now, now=now)
 
111
    getModifiedRemoteBugs([u'a', u'b'], datetime.datetime(...))
 
112
 
 
113
    >>> pprint(ids_to_check)
 
114
    {'all_remote_ids': [u'a', u'b'],
 
115
     'remote_ids_to_check': [u'a'],
 
116
     'unmodified_remote_ids': [u'b']}
 
117
 
 
118
With just more than batch_size previously checked watches, the remote
 
119
system is queried twice, and we are advised to check two of the
 
120
watches.
 
121
 
 
122
    >>> bug_watches = [
 
123
    ...     factory.makeBugWatch(remote_bug='a'),
 
124
    ...     factory.makeBugWatch(remote_bug='b'),
 
125
    ...     factory.makeBugWatch(remote_bug='c'),
 
126
    ...     ]
 
127
    >>> for bug_watch in bug_watches:
 
128
    ...     removeSecurityProxy(bug_watch).lastchecked = now
 
129
    >>> transaction.commit()
 
130
 
 
131
    >>> ids_to_check = updater._getRemoteIdsToCheck(
 
132
    ...     remote, bug_watches, batch_size=2,
 
133
    ...     server_time=now, now=now)
 
134
    getModifiedRemoteBugs([u'a', u'b'], datetime.datetime(...))
 
135
    getModifiedRemoteBugs([u'c'], datetime.datetime(...))
 
136
 
 
137
    >>> pprint(ids_to_check)
 
138
    {'all_remote_ids': [u'a', u'b', u'c'],
 
139
     'remote_ids_to_check': [u'a', u'c'],
 
140
     'unmodified_remote_ids': [u'b']}