Ran black on sources
This commit is contained in:
parent
5e5f3efc24
commit
db17ece61b
4 changed files with 73 additions and 45 deletions
|
|
@ -2650,40 +2650,46 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
switches.append("loc")
|
||||
|
||||
searchstring = self.lhs
|
||||
|
||||
|
||||
try:
|
||||
# Try grabbing the actual min/max id values by database aggregation
|
||||
qs = ObjectDB.objects.values('id').aggregate(low=Min('id'), high=Max('id'))
|
||||
qs = ObjectDB.objects.values("id").aggregate(low=Min("id"), high=Max("id"))
|
||||
low, high = sorted(qs.values())
|
||||
if not (low and high):
|
||||
raise ValueError(f"{self.__class__.__name__}: Min and max ID not returned by aggregation; falling back to queryset slicing.")
|
||||
raise ValueError(
|
||||
f"{self.__class__.__name__}: Min and max ID not returned by aggregation; falling back to queryset slicing."
|
||||
)
|
||||
except Exception as e:
|
||||
logger.log_trace(e)
|
||||
# If that doesn't work for some reason (empty DB?), guess the lower
|
||||
# If that doesn't work for some reason (empty DB?), guess the lower
|
||||
# bound and do a less-efficient query to find the upper.
|
||||
low, high = 1, ObjectDB.objects.all().order_by("-id").first().id
|
||||
|
||||
|
||||
if self.rhs:
|
||||
try:
|
||||
# Check that rhs is either a valid dbref or dbref range
|
||||
bounds = tuple(sorted(dbref(x, False) for x in re.split('[-\s]+', self.rhs.strip())))
|
||||
|
||||
bounds = tuple(
|
||||
sorted(dbref(x, False) for x in re.split("[-\s]+", self.rhs.strip()))
|
||||
)
|
||||
|
||||
# dbref() will return either a valid int or None
|
||||
assert bounds
|
||||
# None should not exist in the bounds list
|
||||
assert None not in bounds
|
||||
|
||||
|
||||
low = bounds[0]
|
||||
if len(bounds) > 1:
|
||||
high = bounds[-1]
|
||||
|
||||
|
||||
except AssertionError:
|
||||
caller.msg("Invalid dbref range provided (not a number).")
|
||||
return
|
||||
except IndexError as e:
|
||||
logger.log_err(f"{self.__class__.__name__}: Error parsing upper and lower bounds of query.")
|
||||
logger.log_err(
|
||||
f"{self.__class__.__name__}: Error parsing upper and lower bounds of query."
|
||||
)
|
||||
logger.log_trace(e)
|
||||
|
||||
|
||||
low = min(low, high)
|
||||
high = max(low, high)
|
||||
|
||||
|
|
@ -2754,36 +2760,45 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
|
|||
# Keep the initial queryset handy for later reuse
|
||||
result_qs = ObjectDB.objects.filter(keyquery | aliasquery).distinct()
|
||||
nresults = result_qs.count()
|
||||
|
||||
|
||||
# Use iterator to minimize memory ballooning on large result sets
|
||||
results = result_qs.iterator()
|
||||
|
||||
|
||||
# Check and see if type filtering was requested; skip it if not
|
||||
if any(x in switches for x in ("room", "exit", "char")):
|
||||
obj_ids = set()
|
||||
for obj in results:
|
||||
if ("room" in switches and 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 (
|
||||
("room" in switches and 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))
|
||||
):
|
||||
obj_ids.add(obj.id)
|
||||
|
||||
|
||||
# Filter previous queryset instead of requesting another
|
||||
filtered_qs = result_qs.filter(id__in=obj_ids).distinct()
|
||||
nresults = filtered_qs.count()
|
||||
|
||||
|
||||
# Use iterator again to minimize memory ballooning
|
||||
results = filtered_qs.iterator()
|
||||
|
||||
# still results after type filtering?
|
||||
if nresults:
|
||||
if nresults > 1: header = f'{nresults} Matches'
|
||||
else: header = 'One Match'
|
||||
|
||||
if nresults > 1:
|
||||
header = f"{nresults} Matches"
|
||||
else:
|
||||
header = "One Match"
|
||||
|
||||
string = f"|w{header}|n(#{low}-#{high}{restrictions}):"
|
||||
res = None
|
||||
for res in results:
|
||||
string += f"\n |g{res.get_display_name(caller)} - {res.path}|n"
|
||||
if "loc" in self.switches and nresults == 1 and res and getattr(res, 'location', None):
|
||||
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)"
|
||||
else:
|
||||
string = f"|wNo Matches|n(#{low}-#{high}{restrictions}):"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue