Resolve "Rider location caching" #1063

Merged
jankstudio merged 8 commits from 180-rider-location-caching into master 2019-05-28 03:24:23 +00:00
2 changed files with 21 additions and 20 deletions
Showing only changes of commit e61d77ad8b - Show all commits

View file

@ -26,6 +26,7 @@ use App\Service\InvoiceCreator;
use App\Service\RisingTideGateway;
use App\Service\MQTTClient;
use App\Service\GeofenceTracker;
use App\Service\RiderTracker;
use App\Entity\MobileSession;
use App\Entity\Customer;
@ -1116,7 +1117,7 @@ class APIController extends Controller
return $res->getReturnResponse();
}
public function getRiderStatus(Request $req)
public function getRiderStatus(Request $req, RiderTracker $rt)
{
$required_params = [];
$em = $this->getDoctrine()->getManager();
@ -1243,8 +1244,9 @@ class APIController extends Controller
case JOStatus::ASSIGNED:
case JOStatus::IN_TRANSIT:
case JOStatus::IN_PROGRESS:
$coord = $jo->getHub()->getCoordinates();
$rider = $jo->getRider();
// get rider coordinates from redis
$coord = $rt->getRiderLocation($rider->getID());
// default image url
$url_prefix = $req->getSchemeAndHttpHost();

View file

@ -33,26 +33,25 @@ class RiderTracker
public function getRiderLocation($rider_id)
{
// check if rider id exists or is valid
$rider = $this->em->getRepository(Rider::class)->find($rider_id);
if ($rider != null)
$coordinates = new Point(0,0);
$key = $this->getRiderKey($rider_id);
// check redis cache for rider information
if (($this->redis->hexists($key, 'longitude')) &&
($this->redis->hexists($key, 'latitude')))
{
$coordinates = $rider->getHub()->getCoordinates();
$key = $this->getRiderKey($rider_id);
// check redis cache for rider information
if (($this->redis->hexists($key, 'longitude')) &&
($this->redis->hexists($key, 'latitude')))
{
$long = $this->redis->hget($key, 'longitude');
$lat = $this->redis->hget($key, 'latitude');
$coordinates = new Point($long, $lat);
}
return $coordinates;
$long = $this->redis->hget($key, 'longitude');
$lat = $this->redis->hget($key, 'latitude');
$coordinates = new Point($long, $lat);
}
else
{
$rider = $this->em->getRepository(Rider::class)->find($rider_id);
$coordinates = $rider->getHub()->getCoordinates();
}
return $coordinates;
}
}