Handle counting number of fits per ship category more efficiently (see #819)
This commit is contained in:
@@ -306,24 +306,31 @@ def countAllFits():
|
|||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
def countFitsWithShip(shipID, ownerID=None, where=None, eager=None):
|
def countFitsWithShip(lookfor, ownerID=None, where=None, eager=None):
|
||||||
"""
|
"""
|
||||||
Get all the fits using a certain ship.
|
Get all the fits using a certain ship.
|
||||||
If no user is passed, do this for all users.
|
If no user is passed, do this for all users.
|
||||||
"""
|
"""
|
||||||
if isinstance(shipID, int):
|
if ownerID is not None and not isinstance(ownerID, int):
|
||||||
if ownerID is not None and not isinstance(ownerID, int):
|
raise TypeError("OwnerID must be integer")
|
||||||
raise TypeError("OwnerID must be integer")
|
|
||||||
filter = Fit.shipID == shipID
|
|
||||||
if ownerID is not None:
|
|
||||||
filter = and_(filter, Fit.ownerID == ownerID)
|
|
||||||
|
|
||||||
filter = processWhere(filter, where)
|
if isinstance(lookfor, int):
|
||||||
eager = processEager(eager)
|
filter = Fit.shipID == lookfor
|
||||||
with sd_lock:
|
elif isinstance(lookfor, list):
|
||||||
count = saveddata_session.query(Fit).options(*eager).filter(filter).count()
|
if len(lookfor) == 0:
|
||||||
|
return 0
|
||||||
|
filter = Fit.shipID.in_(lookfor)
|
||||||
else:
|
else:
|
||||||
raise TypeError("ShipID must be integer")
|
raise TypeError("You must supply either an integer or ShipID must be integer")
|
||||||
|
|
||||||
|
if ownerID is not None:
|
||||||
|
filter = and_(filter, Fit.ownerID == ownerID)
|
||||||
|
|
||||||
|
filter = processWhere(filter, where)
|
||||||
|
eager = processEager(eager)
|
||||||
|
with sd_lock:
|
||||||
|
count = saveddata_session.query(Fit).options(*eager).filter(filter).count()
|
||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ Stage3Selected, EVT_SB_STAGE3_SEL = wx.lib.newevent.NewEvent()
|
|||||||
SearchSelected, EVT_SB_SEARCH_SEL = wx.lib.newevent.NewEvent()
|
SearchSelected, EVT_SB_SEARCH_SEL = wx.lib.newevent.NewEvent()
|
||||||
ImportSelected, EVT_SB_IMPORT_SEL = wx.lib.newevent.NewEvent()
|
ImportSelected, EVT_SB_IMPORT_SEL = wx.lib.newevent.NewEvent()
|
||||||
|
|
||||||
|
|
||||||
class PFWidgetsContainer(PFListPane):
|
class PFWidgetsContainer(PFListPane):
|
||||||
def __init__(self,parent):
|
def __init__(self,parent):
|
||||||
PFListPane.__init__(self,parent)
|
PFListPane.__init__(self,parent)
|
||||||
@@ -685,7 +686,8 @@ class ShipBrowser(wx.Panel):
|
|||||||
|
|
||||||
# set map & cache of fittings per category
|
# set map & cache of fittings per category
|
||||||
for cat in self.categoryList:
|
for cat in self.categoryList:
|
||||||
self.categoryFitCache[cat.ID] = sFit.groupHasFits(cat.ID)
|
itemIDs = [x.ID for x in cat.items]
|
||||||
|
self.categoryFitCache[cat.ID] = sFit.countFitsWithShip(itemIDs) > 1
|
||||||
|
|
||||||
for ship in self.categoryList:
|
for ship in self.categoryList:
|
||||||
if self.filterShipsWithNoFits and not self.categoryFitCache[ship.ID]:
|
if self.filterShipsWithNoFits and not self.categoryFitCache[ship.ID]:
|
||||||
|
|||||||
@@ -142,19 +142,10 @@ class Fit(object):
|
|||||||
def countAllFits(self):
|
def countAllFits(self):
|
||||||
return eos.db.countAllFits()
|
return eos.db.countAllFits()
|
||||||
|
|
||||||
def countFitsWithShip(self, shipID):
|
def countFitsWithShip(self, stuff):
|
||||||
count = eos.db.countFitsWithShip(shipID)
|
count = eos.db.countFitsWithShip(stuff)
|
||||||
return count
|
return count
|
||||||
|
|
||||||
def groupHasFits(self, groupID):
|
|
||||||
sMkt = Market.getInstance()
|
|
||||||
grp = sMkt.getGroup(groupID)
|
|
||||||
items = sMkt.getItemsByGroup(grp)
|
|
||||||
for item in items:
|
|
||||||
if self.countFitsWithShip(item.ID) > 0:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def getModule(self, fitID, pos):
|
def getModule(self, fitID, pos):
|
||||||
fit = eos.db.getFit(fitID)
|
fit = eos.db.getFit(fitID)
|
||||||
return fit.modules[pos]
|
return fit.modules[pos]
|
||||||
|
|||||||
@@ -543,6 +543,7 @@ class Market():
|
|||||||
def getGroupsByCategory(self, cat):
|
def getGroupsByCategory(self, cat):
|
||||||
"""Get groups from given category"""
|
"""Get groups from given category"""
|
||||||
groups = set(filter(lambda grp: self.getPublicityByGroup(grp), cat.groups))
|
groups = set(filter(lambda grp: self.getPublicityByGroup(grp), cat.groups))
|
||||||
|
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
def getMarketGroupChildren(self, mg):
|
def getMarketGroupChildren(self, mg):
|
||||||
|
|||||||
Reference in New Issue
Block a user