Skip to content

Commit 7f88e16

Browse files
authored
Merge pull request #112 from tristanbudd/fix-deploy
Fix deploy error
2 parents 4ed4e13 + 0494944 commit 7f88e16

4 files changed

Lines changed: 47 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ jobs:
1818

1919
- name: Setup pnpm
2020
uses: pnpm/action-setup@v4
21-
with:
22-
version: 9
2321

2422
- name: Setup Node.js
2523
uses: actions/setup-node@v4
2624
with:
27-
node-version: 20
25+
node-version: 22
2826
cache: pnpm
2927

3028
- name: Install dependencies

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ WORKDIR /app
33
COPY composer.json composer.lock ./
44
RUN composer install --no-dev --prefer-dist --no-interaction --no-scripts --optimize-autoloader
55

6-
FROM node:20-alpine AS frontend_build
6+
FROM node:22-alpine AS frontend_build
77
WORKDIR /app
88
COPY package.json pnpm-lock.yaml ./
99
RUN corepack enable && pnpm install --frozen-lockfile

app/Http/Controllers/Api/VesselController.php

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public function sanctionedList(Request $request): JsonResponse
495495
$search = strtolower($request->input('search', ''));
496496
$limit = min((int) $request->input('limit', 100), 500);
497497

498-
$sanctioned = [];
498+
$sanctionedData = [];
499499
$count = 0;
500500

501501
foreach ($vessels as $vessel) {
@@ -505,6 +505,34 @@ public function sanctionedList(Request $request): JsonResponse
505505
continue;
506506
}
507507

508+
$sanctionedData[] = $vessel;
509+
510+
$count++;
511+
if ($count >= $limit) {
512+
break;
513+
}
514+
}
515+
516+
if (empty($sanctionedData)) {
517+
return response()->json([
518+
'message' => 'No sanctioned vessels found in the current records.',
519+
], 404);
520+
}
521+
522+
// Pre-fetch local vessel data to cross-reference ONLY for the limited result set
523+
$mmsis = collect($sanctionedData)->pluck('mmsi')->filter()->toArray();
524+
$imos = collect($sanctionedData)->pluck('imo')->filter()->toArray();
525+
526+
$localVessels = Vessel::whereIn('mmsi', $mmsis)
527+
->orWhereIn('imo', $imos)
528+
->get(['mmsi', 'imo', 'last_seen_at']);
529+
530+
$localByMmsi = $localVessels->whereNotNull('mmsi')->keyBy('mmsi');
531+
$localByImo = $localVessels->whereNotNull('imo')->keyBy('imo');
532+
533+
$sanctioned = [];
534+
foreach ($sanctionedData as $vessel) {
535+
$name = $vessel['name'] ?? '';
508536
$sanctioners = $vessel['sanctioners'] ?? [];
509537
$sanctions_count = is_array($sanctioners) ? count($sanctioners) : 0;
510538

@@ -515,32 +543,33 @@ public function sanctionedList(Request $request): JsonResponse
515543
$risk_level = 'low';
516544
}
517545

546+
$mmsi = isset($vessel['mmsi']) ? (int) $vessel['mmsi'] : null;
547+
$imo = isset($vessel['imo']) ? (int) $vessel['imo'] : null;
548+
549+
$localMatch = null;
550+
if ($mmsi && isset($localByMmsi[$mmsi])) {
551+
$localMatch = $localByMmsi[$mmsi];
552+
} elseif ($imo && isset($localByImo[$imo])) {
553+
$localMatch = $localByImo[$imo];
554+
}
555+
518556
// Using fleetleaks data to construct standardized response
519557
$sanctioned[] = [
520558
'id' => $vessel['id'] ?? null,
521-
'mmsi' => isset($vessel['mmsi']) ? (int) $vessel['mmsi'] : (int) ($vessel['imo'] ?? 0), // fallback for matching
522-
'imo' => isset($vessel['imo']) ? (int) $vessel['imo'] : null,
559+
'mmsi' => $mmsi ?: (int) ($vessel['imo'] ?? 0), // fallback for matching
560+
'imo' => $imo,
523561
'name' => $name,
524562
'lat' => (float) ($vessel['latitude'] ?? 0),
525563
'lng' => (float) ($vessel['longitude'] ?? 0),
526564
'course' => (float) ($vessel['course_degrees'] ?? 0),
527-
'last_seen_at' => $vessel['location_last_updated'] ?? now()->toIso8601String(),
565+
'last_seen_at' => $vessel['location_last_updated'] ?? null,
566+
'sist_last_seen_at' => $localMatch ? $localMatch->last_seen_at?->toIso8601String() : null,
567+
'in_sist' => ! is_null($localMatch),
528568
'is_sanctioned' => true,
529569
'risk_level' => $risk_level,
530570
'sanctions_count' => $sanctions_count,
531571
'sanctioners' => $sanctioners,
532572
];
533-
534-
$count++;
535-
if ($count >= $limit) {
536-
break;
537-
}
538-
}
539-
540-
if (empty($sanctioned)) {
541-
return response()->json([
542-
'message' => 'No sanctioned vessels found in the current records.',
543-
], 404);
544573
}
545574

546575
return response()->json(['data' => $sanctioned]);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"license": "MIT",
88
"private": true,
99
"type": "module",
10+
"packageManager": "pnpm@10.30.3",
1011
"repository": {
1112
"type": "git",
1213
"url": "https://github.com/tristanbudd/sist.git"

0 commit comments

Comments
 (0)