Removes extraneous codeblock, fixes generator reuse, and addresses an unbound local error with rendering.
This commit is contained in:
parent
54b2572538
commit
3725d94e88
1 changed files with 21 additions and 37 deletions
|
|
@ -2806,18 +2806,6 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
||||||
if len(bounds) > 1:
|
if len(bounds) > 1:
|
||||||
high = bounds[-1]
|
high = bounds[-1]
|
||||||
|
|
||||||
"""
|
|
||||||
if "-" in self.rhs:
|
|
||||||
# also support low-high syntax
|
|
||||||
limlist = [part.lstrip("#").strip() for part in self.rhs.split("-", 1)]
|
|
||||||
else:
|
|
||||||
# otherwise split by space
|
|
||||||
limlist = [part.lstrip("#") for part in self.rhs.split(None, 1)]
|
|
||||||
if limlist and limlist[0].isdigit():
|
|
||||||
low = max(low, int(limlist[0]))
|
|
||||||
if len(limlist) > 1 and limlist[1].isdigit():
|
|
||||||
high = min(high, int(limlist[1]))
|
|
||||||
"""
|
|
||||||
low = min(low, high)
|
low = min(low, high)
|
||||||
high = max(low, high)
|
high = max(low, high)
|
||||||
|
|
||||||
|
|
@ -2894,33 +2882,28 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
||||||
id__lte=high,
|
id__lte=high,
|
||||||
)
|
)
|
||||||
|
|
||||||
results = ObjectDB.objects.filter(keyquery | aliasquery).distinct()
|
# Keep the initial queryset handy for later reuse
|
||||||
nresults = results.count()
|
result_qs = ObjectDB.objects.filter(keyquery | aliasquery).distinct()
|
||||||
|
nresults = result_qs.count()
|
||||||
|
|
||||||
# Use iterator to minimize memory ballooning on large result sets
|
# Use iterator to minimize memory ballooning on large result sets
|
||||||
results = results.iterator()
|
results = result_qs.iterator()
|
||||||
|
|
||||||
if nresults:
|
# Check and see if type filtering was requested; skip it if not
|
||||||
# filter results by typeclasses, if requested
|
if any(x in switches for x in ("room", "exit", "char")):
|
||||||
obj_ids = []
|
obj_ids = set()
|
||||||
if "room" in switches:
|
for obj in results:
|
||||||
obj_ids.extend([
|
if ("room" in switches and inherits_from(obj, ROOM_TYPECLASS)) \
|
||||||
obj.id for obj in results if inherits_from(obj, ROOM_TYPECLASS)
|
or ("exit" in switches and inherits_from(obj, EXIT_TYPECLASS)) \
|
||||||
])
|
or ("char" in switches and inherits_from(obj, CHAR_TYPECLASS)):
|
||||||
if "exit" in switches:
|
obj_ids.add(obj.id)
|
||||||
obj_ids.extend([
|
|
||||||
obj.id for obj in results if inherits_from(obj, EXIT_TYPECLASS)
|
# Filter previous queryset instead of requesting another
|
||||||
])
|
filtered_qs = result_qs.filter(id__in=obj_ids).distinct()
|
||||||
if "char" in switches:
|
nresults = filtered_qs.count()
|
||||||
obj_ids.extend([
|
|
||||||
obj.id for obj in results if inherits_from(obj, CHAR_TYPECLASS)
|
|
||||||
])
|
|
||||||
if obj_ids:
|
|
||||||
filtered_result_qs = ObjectDB.objects.filter(id__in=set(obj_ids)).distinct()
|
|
||||||
nresults = filtered_result_qs.count()
|
|
||||||
|
|
||||||
# Keep using iterator to minimize memory ballooning
|
# Keep using iterator to minimize memory ballooning
|
||||||
results = filtered_result_qs.iterator()
|
results = filtered_qs.iterator()
|
||||||
|
|
||||||
# still results after type filtering?
|
# still results after type filtering?
|
||||||
if nresults:
|
if nresults:
|
||||||
|
|
@ -2928,9 +2911,10 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
||||||
else: header = 'One Match'
|
else: header = 'One Match'
|
||||||
|
|
||||||
string = f"|w{header}|n(#{low}-#{high}{restrictions}):"
|
string = f"|w{header}|n(#{low}-#{high}{restrictions}):"
|
||||||
|
res = None
|
||||||
for res in results:
|
for res in results:
|
||||||
string += f"\n |g{res.get_display_name(caller)} - {res.path}|n"
|
string += f"\n |g{res.get_display_name(caller)} - {res.path}|n"
|
||||||
if "loc" in self.switches and nresults == 1 and res and res.location:
|
if "loc" in self.switches and nresults == 1 and res and getattr(res, 'location', None):
|
||||||
string += f" (|wlocation|n: |g{res.location.get_display_name(caller)}|n)"
|
string += f" (|wlocation|n: |g{res.location.get_display_name(caller)}|n)"
|
||||||
else:
|
else:
|
||||||
string = "|wMatch|n(#{low}-#{high}{restrictions}):"
|
string = "|wMatch|n(#{low}-#{high}{restrictions}):"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue