Update: 2026-07-04 17:02:24
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
# Redis State Cache Plan
|
||||
|
||||
## New Redis Keys
|
||||
- `ride:{id}:state` (Hash) → status, driver_id, passenger_id, carType, updated_at
|
||||
- `ride:{id}:driver` (Hash) → driver_name, car_model, car_plate, rating, phone (cached)
|
||||
|
||||
## Changes Per File
|
||||
|
||||
### acceptRide.php
|
||||
After MySQL lock succeeds:
|
||||
```php
|
||||
$redis->hmset("ride:$rideId:state", [
|
||||
'status' => $status,
|
||||
'driver_id' => $driverId,
|
||||
'passenger_id'=> $passengerIdValue,
|
||||
'carType' => $carType,
|
||||
'updated_at' => time()
|
||||
]);
|
||||
$redis->expire("ride:$rideId:state", 86400);
|
||||
|
||||
$redis->hmset("ride:$rideId:driver", $driverInfo);
|
||||
$redis->expire("ride:$rideId:driver", 86400);
|
||||
|
||||
$redis->publish("ride:state_changes", json_encode([
|
||||
'ride_id' => $rideId, 'status' => 'accepted',
|
||||
'driver_id' => $driverId, 'passenger_id' => $passengerIdValue
|
||||
]));
|
||||
```
|
||||
|
||||
### start_ride.php
|
||||
```php
|
||||
$redis->hmset("ride:$rideId:state", ['status' => 'Begin', 'updated_at' => time()]);
|
||||
$con_ride->prepare("UPDATE ride SET status = ?, rideTimeStart = NOW() WHERE id = ?")->execute([$status, $ride_id]);
|
||||
$redis->publish("ride:state_changes", [...]);
|
||||
```
|
||||
|
||||
### arrive_ride.php, cancel_ride_*.php
|
||||
Same pattern: Redis update first (or after), then MySQL, then Pub/Sub.
|
||||
|
||||
### finish_ride_updates.php
|
||||
No change to Redis state (keep MySQL transaction as-is).
|
||||
|
||||
## Socket Server Changes (loction_server/driver_socket.php)
|
||||
- Subscribe to Redis `ride:state_changes` channel
|
||||
- On message: update in-memory state, emit to passenger room
|
||||
- Read from `ride:{id}:state` hash instead of MySQL queries
|
||||
+3
@@ -25,6 +25,9 @@ object CarNavigationData {
|
||||
var isNavigating: Boolean = false
|
||||
var currentSpeed: Double = 0.0 // km/h
|
||||
|
||||
// --- إعدادات المظهر ---
|
||||
var isMapDarkMode: Boolean = false // true = dark (style_dark.json), false = light (style.json)
|
||||
|
||||
// --- نظام المستمعين ---
|
||||
private val listeners = mutableListOf<() -> Unit>()
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ class MainActivity : FlutterFragmentActivity() {
|
||||
CarNavigationData.estimatedTimeRemainingSeconds = call.argument<Double>("eta") ?: CarNavigationData.estimatedTimeRemainingSeconds
|
||||
CarNavigationData.maneuverType = call.argument<Int>("maneuver") ?: CarNavigationData.maneuverType
|
||||
CarNavigationData.isNavigating = call.argument<Boolean>("isNavigating") ?: CarNavigationData.isNavigating
|
||||
CarNavigationData.isMapDarkMode = call.argument<Boolean>("isMapDarkMode") ?: CarNavigationData.isMapDarkMode
|
||||
CarNavigationData.notifyListeners()
|
||||
result.success(true)
|
||||
}
|
||||
|
||||
+21
-3
@@ -25,6 +25,21 @@ class MapPresentation(outerContext: Context, display: Display) : Presentation(ou
|
||||
|
||||
private val locationListener: () -> Unit = {
|
||||
updateCameraPosition()
|
||||
reloadStyleIfNeeded()
|
||||
}
|
||||
|
||||
private var currentStyleLoaded: String? = null
|
||||
|
||||
private fun reloadStyleIfNeeded() {
|
||||
val expectedStyle = if (CarNavigationData.isMapDarkMode)
|
||||
"asset://packages/intaleq_maps/assets/style_dark.json"
|
||||
else
|
||||
"asset://packages/intaleq_maps/assets/style.json"
|
||||
|
||||
if (currentStyleLoaded != expectedStyle && isMapReady) {
|
||||
currentStyleLoaded = expectedStyle
|
||||
mapboxMap?.setStyle(Style.Builder().fromUri(expectedStyle)) { isMapReady = true }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -51,9 +66,12 @@ class MapPresentation(outerContext: Context, display: Display) : Presentation(ou
|
||||
mapView.getMapAsync { map ->
|
||||
mapboxMap = map
|
||||
|
||||
// تحميل ستايل خرائط سيرو من أصول فلاتر
|
||||
val styleUrl = "asset://flutter_assets/assets/style.json"
|
||||
map.setStyle(Style.Builder().fromUri(styleUrl)) {
|
||||
// تحميل ستايل خرائط سيرو من حزمة intaleq_maps حسب الوضعية
|
||||
currentStyleLoaded = if (CarNavigationData.isMapDarkMode)
|
||||
"asset://packages/intaleq_maps/assets/style_dark.json"
|
||||
else
|
||||
"asset://packages/intaleq_maps/assets/style.json"
|
||||
map.setStyle(Style.Builder().fromUri(currentStyleLoaded)) {
|
||||
isMapReady = true
|
||||
updateCameraPosition()
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ class CarPlatformBridge {
|
||||
required double eta,
|
||||
required int maneuver,
|
||||
required bool isNavigating,
|
||||
bool isMapDarkMode = false,
|
||||
}) async {
|
||||
try {
|
||||
await _channel.invokeMethod('updateNavState', {
|
||||
@@ -46,6 +47,7 @@ class CarPlatformBridge {
|
||||
'eta': eta,
|
||||
'maneuver': maneuver,
|
||||
'isNavigating': isNavigating,
|
||||
'isMapDarkMode': isMapDarkMode,
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@@ -1347,6 +1347,7 @@ class NavigationController extends GetxController
|
||||
? currentManeuverModifier as int
|
||||
: int.tryParse(currentManeuverModifier.toString()) ?? 0,
|
||||
isNavigating: true,
|
||||
isMapDarkMode: box.read('isMapDarkMode') ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user