def _SortInvoiceDataList_(self, a, b):
cID1 = a.cID
cID2 = b.cID
if cID1 < cID2:
return -1
else:
return int(cID1 > cID2)
środa, 21 listopada 2012
lazy ....
Python, django
companies = list(queryset)
query set is lazy - and it is done like that by purpose so let's 'resolve' it into a list and waste memory and CPU. Beware of using itertools
wtorek, 20 marca 2012
in bigger loop in big loop
it is a big part of very complex class.# Auto XXX if action == 'XXX': Relation = self.GetAXXXRelation(cid, cType) if AXXXRelation: product_AXXX = self.actionModel.ProductManager.GetProductAttrByName("AXXX") if not self.Company[cid].Customer[cust_ID].PriceSet[product_AXXX.ID].priceType == self.priceInterface.PRICETYPE_GLOBAL: for c_record in AXXXRelation: if c_record[0] == tour_id: action = 'AXXX' break
GetAXXXRelation returns a list of tuples to consider - in most cases this list is big.
It contains basic information about transactions that have to be handled in other way.
This part is located in big loop that iterates and transforms all transactions.
Isn't it more nice to use python built-in functions? it might work in the same ( AFAIR 'in' is optimized ) .
Lets look on this example
now comes funny part, because lists are sorted.XXXTransaction id list [2,4,6,8...] allTransaction id list [1,2,3,4...]
Checking if first elements are in XXX lists is quite easy but it is more expensive on the end of list :)
Hint for solution - it will help with code understanding and might be faster!
# Auto XXX if action == 'XXX': #that have to be performed on higher level - to not iterate it on each transaction #I've placed it only to show that now it is list of id not tuples AXXXRelation = [x[0] for x in self.GetAXXXRelation(cid, cType)] if AXXXRelation: product_AXXX = self.actionModel.ProductManager.GetProductAttrByName("AXXX") if not self.Company[cid].Customer[cust_ID].PriceSet[product_AXXX.ID].priceType == self.priceInterface.PRICETYPE_GLOBAL: if tour_id in AXXXRelation: # for c_record in AXXXRelation: # if c_record[0] == tour_id: action = 'AXXX' # break
poniedziałek, 16 stycznia 2012
exception - no one knows!
try:
try:
self.DBHelper.SubCompany_MappingDeleteStdByCID(cursor, ...)
if self.Mode == SUBCOMPANYMAPPINGDIALOG_MODE_ADD:
self.DBHelper.SubCompany_MappingAdd(cursor, ...)
else:
self.DBHelper.SubCompany_MappingReplace(cursor, ...)
DB.commit()
except:
DB.rollback()
finally:
cursor.close()
From my point of view I'd love to know that exception occured!
Subskrybuj:
Posty (Atom)