Mike Howarth wrote: > Having overcome my first hurdle with the factory pattern, I've now hit > another stumbling block > > At the moment I'm trying to return around 2000 records from a db and load up > the relevant product object, what I've found is this is running extremely > slowly (> 20mins), the db is normalized and indexes exist. > > Can anyone advise on how best I could speed this up? > > def getWebRangeProducts(self): > if self.c.connected: > cu = self.c.cursor #create the cursor > sql = "SELECT type, code FROM products" > cu.execute(sql) > if cu.rowcount > 0: > rows = cu.fetchall() > for row in rows: > self.loadProduct(row[0].strip(),row[1].strip()) > return self.products > > def loadProduct(self,type,product_code): > print type + ":" + product_code > if type == 'I': > try: > product = factory('Item', product_code) > self.products.append(product) > except: > print 'problem occured:' + type + ':' + product_code > elif type == 'S': > try: > item_set = factory('Set', product_code) > item_set.getItems() > self.products.extend(item_set.getItems()) > except: > print 'problem occured:' + type + ':' + product_code > else: > pass > There's definitely *something* wrong - this shouldn't take 20 seconds, let alone 20 minutes.
How frequently do you see the print type + ":" + product_code statement producing output? In other words, is the slowness distributed across the task, or is there a delay at the beginning or end? Are the Set and Item classes exactly as shown in your last post? regards Steve PS: Please put your answer at the bottom, not the top! -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden --------------- Asciimercial ------------------ Get on the web: Blog, lens and tag the Internet Many services currently offer free registration ----------- Thank You for Reading ------------- -- http://mail.python.org/mailman/listinfo/python-list