feat: remove logs
This commit is contained in:
parent
23163c9c4c
commit
047292d0c1
|
|
@ -54,166 +54,79 @@ class HuntsController extends Controller
|
||||||
|
|
||||||
private function buildMeilisearchFilters(Request $request): string
|
private function buildMeilisearchFilters(Request $request): string
|
||||||
{
|
{
|
||||||
Log::info('BUILD_FILTERS_START', [
|
|
||||||
'has_participating' => $request->has('participating'),
|
|
||||||
'has_active' => $request->has('active'),
|
|
||||||
'has_city' => $request->filled('city'),
|
|
||||||
'has_difficulty' => $request->filled('difficulty'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$filters = [];
|
$filters = [];
|
||||||
|
|
||||||
// participating
|
// participating
|
||||||
if ($request->has('participating')) {
|
if ($request->has('participating')) {
|
||||||
Log::info('PROCESSING_PARTICIPATING_FILTER', [
|
|
||||||
'participating_raw' => $request->query('participating'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$participating = filter_var(
|
$participating = filter_var(
|
||||||
$request->query('participating'),
|
$request->query('participating'),
|
||||||
FILTER_VALIDATE_BOOLEAN,
|
FILTER_VALIDATE_BOOLEAN,
|
||||||
FILTER_NULL_ON_FAILURE
|
FILTER_NULL_ON_FAILURE
|
||||||
);
|
);
|
||||||
|
|
||||||
Log::info('PARTICIPATING_PARSED', [
|
|
||||||
'participating_value' => $participating,
|
|
||||||
'is_bool' => is_bool($participating),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$userId = auth('sanctum')->id(); // chez toi => UUID string
|
$userId = auth('sanctum')->id(); // chez toi => UUID string
|
||||||
|
|
||||||
Log::info('USER_ID_RETRIEVED', [
|
|
||||||
'user_id' => $userId,
|
|
||||||
'user_id_type' => gettype($userId),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($userId) {
|
if ($userId) {
|
||||||
$escapedUserId = $this->escapeMeiliString((string) $userId);
|
$escapedUserId = $this->escapeMeiliString((string) $userId);
|
||||||
|
|
||||||
Log::info('USER_ID_ESCAPED', [
|
|
||||||
'escaped_user_id' => $escapedUserId,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($participating === true) {
|
if ($participating === true) {
|
||||||
// ✅ UUID => string
|
// ✅ UUID => string
|
||||||
$filter = "participant_ids = \"{$escapedUserId}\"";
|
$filters[] = "participant_ids = \"{$escapedUserId}\"";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_PARTICIPATING_TRUE_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
]);
|
|
||||||
} elseif ($participating === false) {
|
} elseif ($participating === false) {
|
||||||
$filter = "participant_ids != \"{$escapedUserId}\"";
|
$filters[] = "participant_ids != \"{$escapedUserId}\"";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_PARTICIPATING_FALSE_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
} elseif ($participating === true) {
|
} elseif ($participating === true) {
|
||||||
$filter = "id < 0";
|
$filters[] = "id < 0";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_NO_USER_PARTICIPATING_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// active
|
// active
|
||||||
if ($request->has('active')) {
|
if ($request->has('active')) {
|
||||||
Log::info('PROCESSING_ACTIVE_FILTER', [
|
|
||||||
'active_raw' => $request->query('active'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$now = Carbon::now('UTC')->timestamp;
|
$now = Carbon::now('UTC')->timestamp;
|
||||||
$active = filter_var($request->query('active'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
$active = filter_var($request->query('active'), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
||||||
|
|
||||||
Log::info('ACTIVE_PARSED', [
|
|
||||||
'active_value' => $active,
|
|
||||||
'is_bool' => is_bool($active),
|
|
||||||
'now_timestamp' => $now,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($active === true) {
|
if ($active === true) {
|
||||||
// Hunt actif = démarré ET (pas terminé OU pas de date de fin)
|
// Hunt actif = démarré ET (pas terminé OU pas de date de fin)
|
||||||
$filter1 = "start_at_timestamp <= {$now}";
|
$filters[] = "start_at_timestamp <= {$now}";
|
||||||
$filters[] = $filter1;
|
|
||||||
Log::info('ADDED_ACTIVE_START_FILTER', [
|
|
||||||
'filter' => $filter1,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Meilisearch : la syntaxe est 'field EXISTS' et non 'EXISTS field'
|
// Meilisearch : la syntaxe est 'field EXISTS' et non 'EXISTS field'
|
||||||
// Un hunt est actif si end_at_timestamp n'existe pas OU >= now
|
// Un hunt est actif si end_at_timestamp n'existe pas OU >= now
|
||||||
$filter2 = "(end_at_timestamp >= {$now} OR NOT end_at_timestamp EXISTS)";
|
$filters[] = "(end_at_timestamp >= {$now} OR NOT end_at_timestamp EXISTS)";
|
||||||
$filters[] = $filter2;
|
|
||||||
Log::info('ADDED_ACTIVE_END_FILTER', [
|
|
||||||
'filter' => $filter2,
|
|
||||||
]);
|
|
||||||
} elseif ($active === false) {
|
} elseif ($active === false) {
|
||||||
// Hunt non actif = pas encore commencé OU (déjà terminé ET a une date de fin)
|
// Hunt non actif = pas encore commencé OU (déjà terminé ET a une date de fin)
|
||||||
// Si pas de end_at_timestamp, le hunt ne peut pas être terminé
|
// Si pas de end_at_timestamp, le hunt ne peut pas être terminé
|
||||||
$filter = "(start_at_timestamp > {$now} OR (end_at_timestamp < {$now} AND end_at_timestamp EXISTS))";
|
$filters[] = "(start_at_timestamp > {$now} OR (end_at_timestamp < {$now} AND end_at_timestamp EXISTS))";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_NOT_ACTIVE_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// city
|
// city
|
||||||
if ($request->filled('city')) {
|
if ($request->filled('city')) {
|
||||||
Log::info('PROCESSING_CITY_FILTER', [
|
|
||||||
'city_raw' => $request->query('city'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$city = $request->query('city');
|
$city = $request->query('city');
|
||||||
if (is_string($city)) {
|
if (is_string($city)) {
|
||||||
$city = $this->escapeMeiliString($city);
|
$city = $this->escapeMeiliString($city);
|
||||||
$filter = "city = \"{$city}\"";
|
$filters[] = "city = \"{$city}\"";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_CITY_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// difficulty
|
// difficulty
|
||||||
if ($request->filled('difficulty')) {
|
if ($request->filled('difficulty')) {
|
||||||
Log::info('PROCESSING_DIFFICULTY_FILTER', [
|
|
||||||
'difficulty_raw' => $request->query('difficulty'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$difficulties = $request->query('difficulty');
|
$difficulties = $request->query('difficulty');
|
||||||
|
|
||||||
if (is_string($difficulties)) {
|
if (is_string($difficulties)) {
|
||||||
$difficulties = explode(',', $difficulties);
|
$difficulties = explode(',', $difficulties);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info('DIFFICULTY_PARSED', [
|
|
||||||
'difficulties' => $difficulties,
|
|
||||||
'is_array' => is_array($difficulties),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (is_array($difficulties)) {
|
if (is_array($difficulties)) {
|
||||||
$validDifficulties = array_values(array_intersect(
|
$validDifficulties = array_values(array_intersect(
|
||||||
HuntDifficulty::values(),
|
HuntDifficulty::values(),
|
||||||
array_map('strtolower', $difficulties)
|
array_map('strtolower', $difficulties)
|
||||||
));
|
));
|
||||||
|
|
||||||
Log::info('VALID_DIFFICULTIES', [
|
|
||||||
'valid_difficulties' => $validDifficulties,
|
|
||||||
'count' => count($validDifficulties),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!empty($validDifficulties)) {
|
if (!empty($validDifficulties)) {
|
||||||
$difficultyFilters = array_map(
|
$difficultyFilters = array_map(
|
||||||
fn ($d) => 'difficulty = "' . $this->escapeMeiliString($d) . '"',
|
fn ($d) => 'difficulty = "' . $this->escapeMeiliString($d) . '"',
|
||||||
$validDifficulties
|
$validDifficulties
|
||||||
);
|
);
|
||||||
$filter = '(' . implode(' OR ', $difficultyFilters) . ')';
|
$filters[] = '(' . implode(' OR ', $difficultyFilters) . ')';
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_DIFFICULTY_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
'difficulty_filters' => $difficultyFilters,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -224,69 +137,34 @@ class HuntsController extends Controller
|
||||||
$endFrom = $this->parseDateFilterUtc($request->query('end_from'));
|
$endFrom = $this->parseDateFilterUtc($request->query('end_from'));
|
||||||
$endTo = $this->parseDateFilterUtc($request->query('end_to'));
|
$endTo = $this->parseDateFilterUtc($request->query('end_to'));
|
||||||
|
|
||||||
Log::info('DATE_FILTERS_PARSED', [
|
|
||||||
'start_from' => $startFrom?->toIso8601String(),
|
|
||||||
'start_to' => $startTo?->toIso8601String(),
|
|
||||||
'end_from' => $endFrom?->toIso8601String(),
|
|
||||||
'end_to' => $endTo?->toIso8601String(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($startFrom) {
|
if ($startFrom) {
|
||||||
// start_at_timestamp est toujours présent (created_at par défaut), donc pas besoin de EXISTS
|
// start_at_timestamp est toujours présent (created_at par défaut), donc pas besoin de EXISTS
|
||||||
$filter = "start_at_timestamp >= {$startFrom->timestamp}";
|
$filters[] = "start_at_timestamp >= {$startFrom->timestamp}";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_START_FROM_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
'timestamp' => $startFrom->timestamp,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
if ($startTo) {
|
if ($startTo) {
|
||||||
// start_at_timestamp est toujours présent
|
// start_at_timestamp est toujours présent
|
||||||
$filter = "start_at_timestamp <= {$startTo->timestamp}";
|
$filters[] = "start_at_timestamp <= {$startTo->timestamp}";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_START_TO_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
'timestamp' => $startTo->timestamp,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
if ($endFrom) {
|
if ($endFrom) {
|
||||||
// end_at_timestamp peut être null, donc on vérifie qu'il existe avant de comparer
|
// end_at_timestamp peut être null, donc on vérifie qu'il existe avant de comparer
|
||||||
$filter = "(end_at_timestamp EXISTS AND end_at_timestamp >= {$endFrom->timestamp})";
|
$filters[] = "(end_at_timestamp EXISTS AND end_at_timestamp >= {$endFrom->timestamp})";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_END_FROM_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
'timestamp' => $endFrom->timestamp,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
if ($endTo) {
|
if ($endTo) {
|
||||||
// end_at_timestamp peut être null, donc on vérifie qu'il existe avant de comparer
|
// end_at_timestamp peut être null, donc on vérifie qu'il existe avant de comparer
|
||||||
$filter = "(end_at_timestamp EXISTS AND end_at_timestamp <= {$endTo->timestamp})";
|
$filters[] = "(end_at_timestamp EXISTS AND end_at_timestamp <= {$endTo->timestamp})";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_END_TO_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
'timestamp' => $endTo->timestamp,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filtre par défaut : si aucun filtre n'est spécifié, afficher uniquement les hunts publics
|
// Filtre par défaut : si aucun filtre n'est spécifié, afficher uniquement les hunts publics
|
||||||
// Cela évite l'erreur Meilisearch avec une chaîne de filtres vide
|
// Cela évite l'erreur Meilisearch avec une chaîne de filtres vide
|
||||||
if (empty($filters)) {
|
if (empty($filters)) {
|
||||||
// En Meilisearch, les booléens peuvent être comparés avec true/false (sans guillemets)
|
// En Meilisearch, les booléens peuvent être comparés avec true/false (sans guillemets)
|
||||||
$filter = "is_public = true";
|
$filters[] = "is_public = true";
|
||||||
$filters[] = $filter;
|
|
||||||
Log::info('ADDED_DEFAULT_PUBLIC_FILTER', [
|
|
||||||
'filter' => $filter,
|
|
||||||
'reason' => 'no_filters_provided',
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$finalFilters = implode(' AND ', $filters);
|
$finalFilters = implode(' AND ', $filters);
|
||||||
|
|
||||||
Log::info('BUILD_FILTERS_COMPLETE', [
|
Log::info('BUILD_FILTERS_COMPLETE', [
|
||||||
'filters_array' => $filters,
|
|
||||||
'filters_count' => count($filters),
|
|
||||||
'final_filters' => $finalFilters,
|
'final_filters' => $finalFilters,
|
||||||
'final_filters_length' => strlen($finalFilters),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $finalFilters;
|
return $finalFilters;
|
||||||
|
|
|
||||||
|
|
@ -106,37 +106,20 @@ class Hunts extends Model
|
||||||
*/
|
*/
|
||||||
public function toSearchableArray(): array
|
public function toSearchableArray(): array
|
||||||
{
|
{
|
||||||
\Illuminate\Support\Facades\Log::info('TO_SEARCHABLE_ARRAY_START', [
|
|
||||||
'hunt_id' => $this->id,
|
|
||||||
'hunt_title' => $this->title,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$status = $this->status instanceof HuntStatus ? $this->status->value : $this->status;
|
$status = $this->status instanceof HuntStatus ? $this->status->value : $this->status;
|
||||||
$difficulty = $this->difficulty instanceof HuntDifficulty ? $this->difficulty->value : $this->difficulty;
|
$difficulty = $this->difficulty instanceof HuntDifficulty ? $this->difficulty->value : $this->difficulty;
|
||||||
|
|
||||||
\Illuminate\Support\Facades\Log::info('TO_SEARCHABLE_ARRAY_ENUMS_CONVERTED', [
|
|
||||||
'hunt_id' => $this->id,
|
|
||||||
'status' => $status,
|
|
||||||
'difficulty' => $difficulty,
|
|
||||||
]);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$participantIds = $this->participants()->pluck('user_id')->toArray();
|
$participantIds = $this->participants()->pluck('user_id')->toArray();
|
||||||
\Illuminate\Support\Facades\Log::info('TO_SEARCHABLE_ARRAY_PARTICIPANTS_LOADED', [
|
|
||||||
'hunt_id' => $this->id,
|
|
||||||
'participant_count' => count($participantIds),
|
|
||||||
'participant_ids' => $participantIds,
|
|
||||||
]);
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
\Illuminate\Support\Facades\Log::error('TO_SEARCHABLE_ARRAY_PARTICIPANTS_ERROR', [
|
\Illuminate\Support\Facades\Log::error('TO_SEARCHABLE_ARRAY_PARTICIPANTS_ERROR', [
|
||||||
'hunt_id' => $this->id,
|
'hunt_id' => $this->id,
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
'trace' => $e->getTraceAsString(),
|
|
||||||
]);
|
]);
|
||||||
$participantIds = [];
|
$participantIds = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$searchableArray = [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'slug' => $this->slug,
|
'slug' => $this->slug,
|
||||||
|
|
@ -157,12 +140,5 @@ class Hunts extends Model
|
||||||
// IDs des participants pour le filtre de participation
|
// IDs des participants pour le filtre de participation
|
||||||
'participant_ids' => $participantIds,
|
'participant_ids' => $participantIds,
|
||||||
];
|
];
|
||||||
|
|
||||||
\Illuminate\Support\Facades\Log::info('TO_SEARCHABLE_ARRAY_COMPLETE', [
|
|
||||||
'hunt_id' => $this->id,
|
|
||||||
'array_keys' => array_keys($searchableArray),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $searchableArray;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue