fix: test

This commit is contained in:
hashbro
2026-09-10 04:49:10 +08:00
parent 9333095103
commit 9651b91d84
5 changed files with 133 additions and 30 deletions
@@ -13,6 +13,7 @@ use App\Services\EthKeystore;
use App\Support\AgentScope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class KeystoreController extends Controller
{
@@ -50,12 +51,34 @@ class KeystoreController extends Controller
$limit = max(1, min(100, (int) $request->query('limit', 20)));
$page = max(1, (int) $request->query('page', 1));
$paginator = $q->paginate($limit, ['*'], 'page', $page);
$cols = array_merge(WalletKeystore::listColumns(), [
'devices.device_id as device_key',
'devices.channel_id as device_channel_id',
]);
Log::info('keystore.list.data.start', [
'page' => $page,
'limit' => $limit,
'mem' => memory_get_usage(true),
]);
$paginator = $q->paginate($limit, $cols, 'page', $page);
Log::info('keystore.list.data.page', [
'total' => $paginator->total(),
'ids' => collect($paginator->items())->pluck('id')->all(),
'sizes' => collect($paginator->items())->mapWithKeys(
static fn (WalletKeystore $row) => [$row->id => (int) ($row->raw_json_len ?? 0)]
)->all(),
'mem' => memory_get_usage(true),
]);
$portal = $this->portal();
$data = collect($paginator->items())->map(function (WalletKeystore $row) use ($portal) {
return $this->rowPayload($row, $portal);
})->values();
Log::info('keystore.list.data.done', [
'count' => $data->count(),
'mem' => memory_get_usage(true),
'peak' => memory_get_peak_usage(true),
]);
return response()->json([
'code' => 0,
@@ -71,6 +94,21 @@ class KeystoreController extends Controller
return response()->json(['code' => 1, 'msg' => '无权操作'], 403);
}
$len = (int) WalletKeystore::query()->whereKey($keystore->id)->toBase()->selectRaw('LENGTH(raw_json) as n')->value('n');
Log::info('keystore.items.start', [
'id' => $keystore->id,
'raw_json_len' => $len,
'mem' => memory_get_usage(true),
]);
$items = $keystore->listedItems();
Log::info('keystore.items.done', [
'id' => $keystore->id,
'raw_json_len' => $len,
'item_count' => count($items),
'mem' => memory_get_usage(true),
'peak' => memory_get_peak_usage(true),
]);
return response()->json([
'code' => 0,
'msg' => '',
@@ -79,7 +117,7 @@ class KeystoreController extends Controller
'source' => $keystore->sourceLabel(),
'decrypted' => (int) $keystore->decrypted,
'kind' => $keystore->kindLabel(),
'items' => $keystore->listedItems(),
'items' => $items,
],
]);
}
@@ -137,13 +175,7 @@ class KeystoreController extends Controller
*/
public function rowPayload(WalletKeystore $row, string $portal): array
{
try {
$itemCount = $row->itemCount();
$summary = $row->summary();
} catch (\Throwable) {
$itemCount = 0;
$summary = '';
}
$stats = $row->listStats();
return [
'id' => $row->id,
@@ -151,9 +183,9 @@ class KeystoreController extends Controller
'channel_id' => $row->device_channel_id ?? $row->device?->channel_id ?? '',
'source' => $row->sourceLabel(),
'decrypted' => (int) $row->decrypted,
'kind' => $row->kindLabel(),
'item_count' => $itemCount,
'summary' => $summary,
'kind' => $stats['kind'],
'item_count' => $stats['item_count'],
'summary' => $stats['summary'],
'created_at' => optional($row->created_at)->format('Y-m-d H:i:s'),
'detail_url' => route($portal.'.devices.show', ['device' => $row->device_id, 'tab' => 'keystores']),
'items_url' => route($portal.'.keystores.items', $row->id),
@@ -203,11 +235,10 @@ class KeystoreController extends Controller
{
$q = WalletKeystore::query()
->join('devices', 'devices.id', '=', 'wallet_keystores.device_id')
->select([
'wallet_keystores.*',
->select(array_merge(WalletKeystore::listColumns(), [
'devices.device_id as device_key',
'devices.channel_id as device_channel_id',
]);
]));
AgentScope::applyDeviceChannelScope($q, $this->agent());