refactor(firmware): trim comments and name the platform list

Cut the comment blocks that ran past two lines, and rename
platformItems to affectedPlatforms since it holds only the platforms
that have missing firmware, unlike the all-platforms list of the same
name in MissingGamesSection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-08-29 16:46:51 -04:00
parent 24f1d4b44e
commit bec9846718
5 changed files with 20 additions and 33 deletions

View File

@@ -46,9 +46,8 @@ class PlatformSchema(BaseModel):
def display_name(self) -> str:
return self.custom_name or self.name
# Counts every row, missing ones included, so it means the same as
# `rom_count`. Callers that want only usable BIOS filter `firmware`,
# which ships with this schema.
# Counts every row like `rom_count` does; callers wanting only usable
# BIOS filter the `firmware` list that ships alongside it.
@computed_field # type: ignore
@property
def firmware_count(self) -> int:

View File

@@ -37,9 +37,8 @@ class DBFirmwareHandler(DBBaseHandler):
hidden_platform_ids: Sequence[int] | None = None,
session: Session = None, # type: ignore
) -> Sequence[Firmware]:
# `Firmware.platform` is `lazy="joined"`, which drags in Platform's
# rom_count / fs_size_bytes aggregate subqueries over `roms`. No
# caller here reads the relationship, so keep it out of the query.
# `Firmware.platform` is lazy="joined", which drags in Platform's
# rom_count and fs_size_bytes subqueries. No caller here reads it.
query = (
select(Firmware)
.options(noload(Firmware.platform))

View File

@@ -1,7 +1,6 @@
<script setup lang="ts">
// Firmware sets are small (dozens per library, not tens of thousands), so the
// whole missing set is fetched once and the platform filter narrows it in
// memory rather than refetching.
// Firmware sets are small (dozens, not tens of thousands), so fetch the whole
// missing set once and narrow it in memory rather than refetching.
import { RBtn, REmptyState, RIcon, RMenu, RMenuItem, RTag } from "@v2/lib";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref } from "vue";
@@ -32,9 +31,8 @@ const loading = ref(true);
const cleaningUp = ref(false);
const selectedPlatformIds = ref<number[]>([]);
// Only platforms that actually have something to clean up: the rest would
// filter the list down to nothing.
const platformItems = computed<Platform[]>(() => {
// Offering an unaffected platform would filter the list down to nothing.
const affectedPlatforms = computed<Platform[]>(() => {
const affected = new Set(missingFirmware.value.map((f) => f.platform_id));
return allPlatforms.value
.filter((p) => affected.has(p.id))
@@ -42,7 +40,7 @@ const platformItems = computed<Platform[]>(() => {
});
const platformById = computed(
() => new Map(platformItems.value.map((p) => [p.id, p])),
() => new Map(affectedPlatforms.value.map((p) => [p.id, p])),
);
const rows = computed(() => {
@@ -121,7 +119,7 @@ onMounted(() => {
<div class="r-v2-missing-fw__toolbar">
<PlatformSelect
v-model="selectedPlatformIds"
:items="platformItems"
:items="affectedPlatforms"
multiple
closable-chips
clearable

View File

@@ -1,6 +1,5 @@
// `POST /tasks/run/{name}` returns as soon as the job is enqueued, so a caller
// that wants to show the job's effect has to wait for the worker. There is no
// socket event for task completion, so poll the job's own status.
// `POST /tasks/run/{name}` returns once the job is enqueued, and no socket
// event reports completion, so poll the job's own status.
import axios from "axios";
import { onScopeDispose } from "vue";
import type { JobStatus } from "@/__generated__";
@@ -34,10 +33,8 @@ export interface UseTaskCompletion {
export function useTaskCompletion(): UseTaskCompletion {
let timer: ReturnType<typeof setTimeout> | null = null;
// The live wait's resolver, which doubles as its identity: a poll still in
// flight compares against it to know whether it was superseded. Cancelling
// clears the pending timer, so it has to settle the outstanding promise
// itself or the caller waits on it forever.
// The live wait's resolver, doubling as its identity so an in-flight poll
// knows it was superseded. Cancelling must settle it or the caller hangs.
let settle: ((observed: boolean) => void) | null = null;
function cancel() {
@@ -70,10 +67,8 @@ export function useTaskCompletion(): UseTaskCompletion {
if (TERMINAL_STATUSES.includes(data.status)) return finish(true);
} catch (err) {
if (settle !== resolve) return;
// A job past its result TTL 404s, which means it ran and is gone.
// Anything else (a timeout, a 5xx) says nothing about the job, so
// keep polling rather than refreshing over a cleanup still in
// progress. The deadline below still bounds the wait.
// A job past its result TTL 404s, so it ran and is gone. Anything
// else says nothing about it, so keep polling until the deadline.
if (axios.isAxiosError(err) && err.response?.status === 404) {
return finish(true);
}

View File

@@ -1,8 +1,5 @@
// Choosing which firmware (BIOS) the EmulatorJS player boots with.
//
// A platform whose only BIOS is gone boots with none rather than with a file
// the server can't serve. The caller already fetches with `missing: false`;
// re-filtering keeps that rule true for any other caller.
// Which firmware (BIOS) the EmulatorJS player boots with. Missing entries are
// never selectable, so a platform whose only BIOS is gone boots with none.
// Only these fields are read, so both `FirmwareSchema` and lighter shapes fit.
interface FirmwareLike {
@@ -19,9 +16,8 @@ export function resolveInitialFirmware<T extends FirmwareLike>({
options: readonly T[];
// The user's last pick for this platform, from localStorage.
storedBiosId: string | null;
// `bios_file` from the selected core's EJS config. Typed as the config's
// own `string | boolean` since most EJS settings are toggles; only a
// string names a file.
// `bios_file` from the core's EJS config, typed `string | boolean` because
// most EJS settings are toggles; only a string names a file.
configBiosFile: string | boolean | undefined;
}): T | null {
const usable = options.filter((f) => !f.missing_from_fs);