Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 2 additions & 56 deletions addon/utils/identity-cell-resource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { get } from '@ember/object';

export { buildIdentityStub } from '@fleetbase/fleetops-data/utils/identity-stub';

export function resolveIdentityCellResource(args) {
const column = args.column ?? {};
const resourcePath = column.resourcePath;
Expand All @@ -18,59 +20,3 @@ export function resolveIdentityCellResource(args) {

return args.row;
}

const inflight = new WeakMap();

/**
* A stand-in for a related record a row only knows by name: enough for an
* identity cell to render (`name`, `resourceType`) and a `loadResource()`
* the cell, pill or summary calls when the real record is needed. The
* stub never carries a UUID in an identifier field, so nothing renders one
* as a plate or an id, and concurrent loads of the same row share one
* request.
*
* `load` receives the row and returns the record (or a promise of it); with
* no `load`, `loadResource()` resolves to null and the stub stays static.
*/
export function buildIdentityStub(row, { type, nameKey = `${type}_name`, name, load, extra = {} } = {}) {
const label = name ?? (row ? get(row, nameKey) : null);

if (!label) {
return null;
}

const stub = {
...extra,
name: label,
display_name: label,
displayName: label,
resourceType: type,
isIdentityStub: true,
loadResource: async () => {
if (typeof load !== 'function') {
return null;
}

let loads = inflight.get(row);

if (!loads) {
loads = new Map();
inflight.set(row, loads);
}

if (!loads.has(type)) {
loads.set(
type,
Promise.resolve()
.then(() => load(row))
.catch(() => null)
.finally(() => loads.delete(type))
);
}

return loads.get(type);
},
};

return stub;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Fleetbase\FleetOps\Support\Database\TableIndexes;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
* fleetops:prune-telematics-data purges soft-deleted rows on every run; without an
* index on deleted_at that sweep walks the whole table even when nothing is trashed.
*/
return new class extends Migration {
private const TABLE = 'device_events';
private const INDEX = 'device_events_company_deleted_at_index';
private const COLUMNS = ['company_uuid', 'deleted_at'];

public function up(): void
{
if (!Schema::hasTable(self::TABLE) || !Schema::hasColumns(self::TABLE, self::COLUMNS)) {
return;
}

if (TableIndexes::covers(self::TABLE, self::COLUMNS)) {
return;
}

Schema::table(self::TABLE, fn (Blueprint $table) => $table->index(self::COLUMNS, self::INDEX));
}

public function down(): void
{
if (!Schema::hasTable(self::TABLE)) {
return;
}

if ((TableIndexes::for(self::TABLE)[self::INDEX] ?? null) === self::COLUMNS) {
Schema::table(self::TABLE, fn (Blueprint $table) => $table->dropIndex(self::INDEX));
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Fleetbase\FleetOps\Support\Database\TableIndexes;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
* fleetops:prune-telematics-data purges soft-deleted rows on every run; without an
* index on deleted_at that sweep walks the whole table even when nothing is trashed.
*/
return new class extends Migration {
private const TABLE = 'positions';
private const INDEX = 'positions_company_deleted_at_index';
private const COLUMNS = ['company_uuid', 'deleted_at'];

public function up(): void
{
if (!Schema::hasTable(self::TABLE) || !Schema::hasColumns(self::TABLE, self::COLUMNS)) {
return;
}

if (TableIndexes::covers(self::TABLE, self::COLUMNS)) {
return;
}

Schema::table(self::TABLE, fn (Blueprint $table) => $table->index(self::COLUMNS, self::INDEX));
}

public function down(): void
{
if (!Schema::hasTable(self::TABLE)) {
return;
}

if ((TableIndexes::for(self::TABLE)[self::INDEX] ?? null) === self::COLUMNS) {
Schema::table(self::TABLE, fn (Blueprint $table) => $table->dropIndex(self::INDEX));
}
}
};
Loading
Loading