Skip to content

Commit efb37f1

Browse files
author
Roche Compaan
committed
Performance tuning.
. Modified cgi interface to change properties only once all changes are collected, files created and messages generated. . Moved generation of change note to nosyreactors. . We now check for changes to "assignedto" to ensure it's added to the nosy list.
1 parent 91a6312 commit efb37f1

File tree

5 files changed

+164
-105
lines changed

5 files changed

+164
-105
lines changed

roundup/cgi_client.py

Lines changed: 83 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: cgi_client.py,v 1.81 2001-12-12 23:55:00 richard Exp $
18+
# $Id: cgi_client.py,v 1.82 2001-12-15 19:24:39 rochecompaan Exp $
1919

2020
__doc__ = """
2121
WWW request handler (also used in the stand-alone server).
@@ -314,32 +314,10 @@ def shownode(self, message=None):
314314
try:
315315
props, changed = parsePropsFromForm(self.db, cl, self.form,
316316
self.nodeid)
317-
318-
# set status to chatting if 'unread' or 'resolved'
319-
if not changed.has_key('status'):
320-
try:
321-
# determine the id of 'unread','resolved' and 'chatting'
322-
unread_id = self.db.status.lookup('unread')
323-
resolved_id = self.db.status.lookup('resolved')
324-
chatting_id = self.db.status.lookup('chatting')
325-
except KeyError:
326-
pass
327-
else:
328-
if (not props.has_key('status') or
329-
props['status'] == unread_id or
330-
props['status'] == resolved_id):
331-
props['status'] = chatting_id
332-
changed['status'] = chatting_id
333-
334-
# get the change note
335-
change_note = cl.generateChangeNote(self.nodeid, changed)
336-
337-
# make the changes
338-
cl.set(self.nodeid, **props)
339-
340-
# handle linked nodes and change message generation
341-
self._post_editnode(self.nodeid, change_note)
342-
317+
# make changes to the node
318+
self._changenode(props)
319+
# handle linked nodes
320+
self._post_editnode(self.nodeid)
343321
# and some nice feedback for the user
344322
if changed:
345323
message = _('%(changes)s edited ok')%{'changes':
@@ -455,37 +433,52 @@ def _createnode(self):
455433
pass
456434
else:
457435
props['status'] = unread_id
436+
# add assignedto to the nosy list
437+
if props.has_key('assignedto'):
438+
assignedto_id = props['assignedto']
439+
if props.has_key('nosy') and not assignedto_id in props['nosy']:
440+
props['nosy'].append(assignedto_id)
441+
else:
442+
props['nosy'] = [assignedto_id]
443+
# check for messages
444+
message = self._handle_message()
445+
if message:
446+
props['messages'] = [message]
447+
# create the node and return it's id
458448
return cl.create(**props)
459449

460-
def _post_editnode(self, nid, change_note=''):
461-
''' do the linking and message sending part of the node creation
450+
def _changenode(self, props):
451+
''' change the node based on the contents of the form
462452
'''
463-
cn = self.classname
464-
cl = self.db.classes[cn]
465-
# link if necessary
466-
keys = self.form.keys()
467-
for key in keys:
468-
if key == ':multilink':
469-
value = self.form[key].value
470-
if type(value) != type([]): value = [value]
471-
for value in value:
472-
designator, property = value.split(':')
473-
link, nodeid = roundupdb.splitDesignator(designator)
474-
link = self.db.classes[link]
475-
value = link.get(nodeid, property)
476-
value.append(nid)
477-
link.set(nodeid, **{property: value})
478-
elif key == ':link':
479-
value = self.form[key].value
480-
if type(value) != type([]): value = [value]
481-
for value in value:
482-
designator, property = value.split(':')
483-
link, nodeid = roundupdb.splitDesignator(designator)
484-
link = self.db.classes[link]
485-
link.set(nodeid, **{property: nid})
486-
487-
# handle file attachments
488-
files = cl.get(nid, 'files')
453+
cl = self.db.classes[self.classname]
454+
# set status to chatting if 'unread' or 'resolved'
455+
try:
456+
# determine the id of 'unread','resolved' and 'chatting'
457+
unread_id = self.db.status.lookup('unread')
458+
resolved_id = self.db.status.lookup('resolved')
459+
chatting_id = self.db.status.lookup('chatting')
460+
except KeyError:
461+
pass
462+
else:
463+
if (props['status'] == unread_id or props['status'] == resolved_id):
464+
props['status'] = chatting_id
465+
# add assignedto to the nosy list
466+
if props.has_key('assignedto'):
467+
assignedto_id = props['assignedto']
468+
if not assignedto_id in props['nosy']:
469+
props['nosy'].append(assignedto_id)
470+
# create the message
471+
message = self._handle_message()
472+
if message:
473+
props['messages'] = cl.get(self.nodeid, 'messages') + [message]
474+
# make the changes
475+
cl.set(self.nodeid, **props)
476+
477+
def _handle_message(self):
478+
''' generate and edit message '''
479+
480+
# handle file attachments
481+
files = []
489482
if self.form.has_key('__file'):
490483
file = self.form['__file']
491484
if file.filename:
@@ -495,14 +488,10 @@ def _post_editnode(self, nid, change_note=''):
495488
# create the new file entry
496489
files.append(self.db.file.create(type=mime_type,
497490
name=file.filename, content=file.file.read()))
498-
# and save the reference
499-
cl.set(nid, files=files)
500-
501-
#
502-
# generate an edit message
503-
#
504491

505492
# we don't want to do a message if none of the following is true...
493+
cn = self.classname
494+
cl = self.db.classes[self.classname]
506495
props = cl.getprops()
507496
note = None
508497
if self.form.has_key('__note'):
@@ -513,7 +502,7 @@ def _post_editnode(self, nid, change_note=''):
513502
return
514503
if not props['messages'].classname == 'msg':
515504
return
516-
if not (len(cl.get(nid, 'nosy', [])) or note):
505+
if not (self.form.has_key('nosy') or note):
517506
return
518507

519508
# handle the note
@@ -528,20 +517,41 @@ def _post_editnode(self, nid, change_note=''):
528517
' the web.\n')%{'classname': cn}
529518
m = [summary]
530519

531-
# append the change note
532-
if change_note:
533-
m.append(change_note)
534-
535520
# now create the message
536521
content = '\n'.join(m)
537522
message_id = self.db.msg.create(author=self.getuid(),
538523
recipients=[], date=date.Date('.'), summary=summary,
539524
content=content, files=files)
540525

541526
# update the messages property
542-
messages = cl.get(nid, 'messages')
543-
messages.append(message_id)
544-
cl.set(nid, messages=messages, files=files)
527+
return message_id
528+
529+
def _post_editnode(self, nid):
530+
''' do the linking part of the node creation
531+
'''
532+
cn = self.classname
533+
cl = self.db.classes[cn]
534+
# link if necessary
535+
keys = self.form.keys()
536+
for key in keys:
537+
if key == ':multilink':
538+
value = self.form[key].value
539+
if type(value) != type([]): value = [value]
540+
for value in value:
541+
designator, property = value.split(':')
542+
link, nodeid = roundupdb.splitDesignator(designator)
543+
link = self.db.classes[link]
544+
value = link.get(nodeid, property)
545+
value.append(nid)
546+
link.set(nodeid, **{property: value})
547+
elif key == ':link':
548+
value = self.form[key].value
549+
if type(value) != type([]): value = [value]
550+
for value in value:
551+
designator, property = value.split(':')
552+
link, nodeid = roundupdb.splitDesignator(designator)
553+
link = self.db.classes[link]
554+
link.set(nodeid, **{property: nid})
545555

546556
def newnode(self, message=None):
547557
''' Add a new node to the database.
@@ -574,7 +584,7 @@ def newnode(self, message=None):
574584
props = {}
575585
try:
576586
nid = self._createnode()
577-
# handle linked nodes and change message generation
587+
# handle linked nodes
578588
self._post_editnode(nid)
579589
# and some nice feedback for the user
580590
message = _('%(classname)s created ok')%{'classname': cn}
@@ -1090,6 +1100,9 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
10901100

10911101
#
10921102
# $Log: not supported by cvs2svn $
1103+
# Revision 1.81 2001/12/12 23:55:00 richard
1104+
# Fixed some problems with user editing
1105+
#
10931106
# Revision 1.80 2001/12/12 23:27:14 richard
10941107
# Added a Zope frontend for roundup.
10951108
#

roundup/mailgw.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.41 2001-12-10 00:57:38 richard Exp $
76+
$Id: mailgw.py,v 1.42 2001-12-15 19:24:39 rochecompaan Exp $
7777
'''
7878

7979

@@ -506,16 +506,14 @@ def handle_message(self, message):
506506
if n.has_key(nid): continue
507507
n[nid] = 1
508508
props['nosy'] = n.keys()
509+
# add assignedto to the nosy list
509510
try:
510511
assignedto = self.db.user.lookup(props['assignedto'])
511512
if assignedto not in props['nosy']:
512513
props['nosy'].append(assignedto)
513514
except:
514515
pass
515516

516-
change_note = cl.generateChangeNote(nodeid, props)
517-
content += change_note
518-
519517
message_id = self.db.msg.create(author=author,
520518
recipients=recipients, date=date.Date('.'), summary=summary,
521519
content=content, files=files)
@@ -572,16 +570,21 @@ def handle_message(self, message):
572570
if self.db.hasnode('user', value):
573571
nid = value
574572
else:
575-
try:
576-
nid = self.db.user.lookup(value)
577-
except:
578-
continue
573+
continue
579574
if n.has_key(nid): continue
580575
n[nid] = 1
581576
props['nosy'] = n.keys() + recipients
577+
# add the author to the nosy list
582578
if not n.has_key(author):
583579
props['nosy'].append(author)
584580
n[author] = 1
581+
# add assignedto to the nosy list
582+
try:
583+
assignedto = self.db.user.lookup(props['assignedto'])
584+
if not n.has_key(assignedto):
585+
props['nosy'].append(assignedto)
586+
except:
587+
pass
585588

586589
# and attempt to create the new node
587590
try:
@@ -620,21 +623,35 @@ def parseContent(content, blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'),
620623
if not section:
621624
continue
622625
lines = eol.split(section)
623-
if lines[0] and lines[0][0] in '>|':
624-
continue
625-
if len(lines) > 1 and lines[1] and lines[1][0] in '>|':
626-
continue
627626
if not summary:
628627
summary = lines[0]
629628
l.append(section)
630629
continue
631-
if signature.match(lines[0]):
632-
break
630+
# TODO: write better pattern for matching signature - it
631+
# currently truncates messages with dashes in
632+
#if signature.match(lines[0]):
633+
# break
633634
l.append(section)
634635
return summary, '\n\n'.join(l)
635636

636637
#
637638
# $Log: not supported by cvs2svn $
639+
# Revision 1.27 2001/12/15 06:51:04 roche
640+
# Merge with CVS
641+
#
642+
# Revision 1.1.1.11 2001/12/13 07:05:43 roche
643+
# update from cvs
644+
#
645+
# Revision 1.41 2001/12/10 00:57:38 richard
646+
# From CHANGES:
647+
# . Added the "display" command to the admin tool - displays a node's values
648+
# . #489760 ] [issue] only subject
649+
# . fixed the doc/index.html to include the quoting in the mail alias.
650+
#
651+
# Also:
652+
# . fixed roundup-admin so it works with transactions
653+
# . disabled the back_anydbm module if anydbm tries to use dumbdbm
654+
#
638655
# Revision 1.40 2001/12/05 14:26:44 rochecompaan
639656
# Removed generation of change note from "sendmessage" in roundupdb.py.
640657
# The change note is now generated when the message is created.

0 commit comments

Comments
 (0)