zucler / Parker

Find a carpark that suits you
Other
0 stars 0 forks source link

Profile and improve front-end database requests #11

Open zucler opened 7 years ago

zucler commented 7 years ago

The code below is not optimised and can cause long delays and broad results.

 parkings = Parking.objects.filter(lat__gte=min_lat, lat__lte=max_lat, long__gte=min_long, long__lte=max_long).all()
    rtype = RateType.objects.filter(parkingID__in=parkings).all()
    rprice = RatePrice.objects.filter(rateID__in=rtype).all()

    # To cache whole querysets
    # FIXME: We need workaround where no extra work done
    bool(parkings)
    bool(rtype)
    bool(rprice)

    parkings = list(geosearch['parkings'])     # Here we have list of dicts
    rtype = geosearch['ratetype']
    rprice = geosearch['rateprice']

        for p_item in parkings:
            sub_ratetype = rtype.filter(parkingID=p_item.parkingID)
            for rt_item in sub_ratetype:
                rt_item.rateprice = list(rprice.filter(rateID=rt_item.rateID))
            p_item.ratetype = sub_ratetype

In general, we need to limit the maximum number of rows returned (e.g. to not return carparks for the entire world) by either:

a) Limiting the difference between min and max lat/long b) Limiting max count of rows returned