I am taking my first stab at using SQLAlchemy and ActiveMapper since I
have a need to use noninteger keys.  (Legacy database.) I am getting
absolutely horrible performance.

The code below selects 10 records from a table and displays the fields,
along with the associated fields from another table which has a one to
one relationship, in a DataGrid.  This should complete almost
instantly.  Instead, it takes 62 seconds on an AMD 64 4000+ with 2GB of
ram.

I see the queries to get the associated fields from Actions go by with
a several second pause in between.

If I leave out the fields from "Actions", it completes in a fraction of
a second.

Obviously I'm doing something very wrong.  But I don't know what.

This is under 1.0b2.

Any advice would be appreciated.

=======================

The Model:

class Contacts(ActiveMapper):
    class mapping:
        ACCOUNTNO = column(String(20), unique=True)
        COMPANY = column(String(40))
        CONTACT = column(String(40))
        LASTNAME = column(String(15))
        DEPARTMENT = column(String(35))
        TITLE = column(String(35))
        SECR = column(String(20))
        PHONE1 = column(String(25))
        PHONE2 = column(String(25))
        PHONE3 = column(String(25))
        FAX = column(String(25))
        EXT1 = column(String( 6))
        EXT2 = column(String( 6))
        EXT3 = column(String( 6))
        EXT4 = column(String( 6))
        ADDRESS1 = column(String(40))
        ADDRESS2 = column(String(40))
        CITY = column(String(30))
        STATE = column(String(20))
        ZIP = column(String(10))
        COUNTRY = column(String(20))
        DEAR = column(String(20))
        SOURCE = column(String(20))
        KEY1 = column(String(20))
        KEY2 = column(String(20))
        KEY3 = column(String(20))
        KEY4 = column(String(20))
        KEY5 = column(String(20))
        STATUS = column(String(3))
        NOTES = column(String(10))
        CREATEBY = column(String( 8))
        OWNER = column(String( 8))
        LASTUSER = column(String( 8))
        LASTDATE = column(String( 8))
        LASTTIME = column(String( 5))
        RECID = column(String(15), primary_key=True)
        actions = one_to_one('Actions', colname='RECID',
backref='contact')


class Actions(ActiveMapper):
    class mapping:
        ACCOUNTNO = column(String(20), index=True)
        CALLBACKON = column(String(25))
        CALLBACKAT = column(String(8))
        LASTCONTON = column(String(25))
        LASTCONTAT = column(String(8))
        LASTATMPON = column(String(25))
        LASTATMPAT = column(String(8))
        MEETDATEON = column(String(25))
        MEETTIMEAT = column(String(8))
        COMMENTS = column(String(65))
        PREVRESULT = column(String(65))
        NEXTACTION = column(String(65))
        RECID = column(String(15), primary_key=True)
        contact_id   = column(Integer,
foreign_key=ForeignKey('contacts.RECID'))

================

The DataGrid:

contacts_form = DataGrid(fields=[
('ACCOUNTNO','ACCOUNTNO'),
('COMPANY','COMPANY'),
('CONTACT','CONTACT'),
('LASTNAME','LASTNAME'),
('DEPARTMENT','DEPARTMENT'),
('TITLE','TITLE'),
('SECR','SECR'),
('PHONE1','PHONE1'),
('PHONE2','PHONE2'),
('PHONE3','PHONE3'),
('FAX','FAX'),
('EXT1','EXT1'),
('EXT2','EXT2'),
('EXT3','EXT3'),
('EXT4','EXT4'),
('ADDRESS1','ADDRESS1'),
('ADDRESS2','ADDRESS2'),
('CITY','CITY'),
('STATE','STATE'),
('ZIP','ZIP'),
('COUNTRY','COUNTRY'),
('DEAR','DEAR'),
('SOURCE','SOURCE'),
('KEY1','KEY1'),
('KEY2','KEY2'),
('KEY3','KEY3'),
('KEY4','KEY4'),
('KEY5','KEY5'),
('STATUS','STATUS'),
('NOTES','NOTES'),
('CREATEBY','CREATEBY'),
('OWNER','OWNER'),
('LASTUSER','LASTUSER'),
('LASTDATE','LASTDATE'),
('LASTTIME','LASTTIME'),
('Call Back On', lambda a: a.actions.CALLBACKON),
('Call Back At', lambda a: a.actions.CALLBACKAT),
('Last Contact On', lambda a: a.actions.LASTCONTON),
('Last Contact At', lambda a: a.actions.LASTCONTAT),
('Last Attempt On', lambda a: a.actions.LASTATMPON),
('Last Attempt At', lambda a: a.actions.LASTATMPAT),
('Meeting Date', lambda a: a.actions.MEETDATEON),
('Meeting Time', lambda a: a.actions.MEETTIMEAT),
('Comments', lambda a: a.actions.COMMENTS),
('Previous Result', lambda a: a.actions.PREVRESULT),
('Next Action', lambda a: a.actions.NEXTACTION)
])

===================

The controller:

    @expose(template='.templates.list')
    def list_contacts(self):
        data=Contacts.select(Contacts.c.COMPANY.startswith('X'))
        return dict(form=contacts_form, data=data)

===================

The template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";
xmlns:py="http://purl.org/kid/ns#";
    py:extends="'master.kid'">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"
py:replace="''"/>
<title>Welcome to TurboGears</title>
</head>
<body>
${form(list(data))}
</body>
</html>

===================


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to