Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: store image maturity in database instead of cache (#263)
Kyle Mendell1b298088172b
diff --git a/src/db/migrations/0005_aberrant_living_lightning.sql b/src/db/migrations/0005_aberrant_living_lightning.sqlnew file mode 100644index 000000000..bb10c4dbd--- /dev/null+++ b/src/db/migrations/0005_aberrant_living_lightning.sql@@ -0,0 +1,49 @@+CREATE TABLE `image_maturity_table` (+ `id` text PRIMARY KEY NOT NULL,+ `repository` text NOT NULL,+ `tag` text NOT NULL,+ `current_version` text NOT NULL,+ `latest_version` text,+ `status` text DEFAULT 'Unknown' NOT NULL,+ `updates_available` integer DEFAULT false NOT NULL,+ `current_image_date` integer,+ `latest_image_date` integer,+ `days_since_creation` integer,+ `registry_domain` text,+ `is_private_registry` integer DEFAULT false NOT NULL,+ `last_checked` integer NOT NULL,+ `check_count` integer DEFAULT 1 NOT NULL,+ `last_error` text,+ `response_time_ms` integer,+ `created_at` integer DEFAULT (unixepoch()) NOT NULL,+ `updated_at` integer DEFAULT (unixepoch()) NOT NULL+);+--> statement-breakpoint+CREATE INDEX `idx_image_maturity_repository` ON `image_maturity_table` (`repository`);--> statement-breakpoint+CREATE INDEX `idx_image_maturity_status` ON `image_maturity_table` (`status`);--> statement-breakpoint+CREATE INDEX `idx_image_maturity_updates` ON `image_maturity_table` (`updates_available`);--> statement-breakpoint+CREATE INDEX `idx_image_maturity_last_checked` ON `image_maturity_table` (`last_checked`);--> statement-breakpoint+CREATE INDEX `idx_image_maturity_repo_tag` ON `image_maturity_table` (`repository`,`tag`);--> statement-breakpoint+CREATE INDEX `idx_image_maturity_status_updates` ON `image_maturity_table` (`status`,`updates_available`);--> statement-breakpoint+CREATE INDEX `idx_image_maturity_registry` ON `image_maturity_table` (`registry_domain`);--> statement-breakpoint+CREATE INDEX `idx_image_maturity_check_count` ON `image_maturity_table` (`check_count`);--> statement-breakpoint+PRAGMA foreign_keys=OFF;--> statement-breakpoint+CREATE TABLE `__new_users_table` (+ `id` text PRIMARY KEY NOT NULL,+ `username` text NOT NULL,+ `password_hash` text,+ `display_name` text,+ `email` text,+ `roles` text DEFAULT '[]' NOT NULL,+ `require_password_change` integer DEFAULT false NOT NULL,+ `oidc_subject_id` text,+ `last_login` integer,+ `created_at` integer DEFAULT (unixepoch() NOT NULL,+ `updated_at` integer DEFAULT (unixepoch()) NOT NULL+);+--> statement-breakpoint+INSERT INTO `__new_users_table`("id", "username", "password_hash", "display_name", "email", "roles", "require_password_change", "oidc_subject_id", "last_login", "created_at", "updated_at") SELECT "id", "username", "password_hash", "display_name", "email", "roles", "require_password_change", "oidc_subject_id", "last_login", "created_at", "updated_at" FROM `users_table`;--> statement-breakpoint+DROP TABLE `users_table`;--> statement-breakpoint+ALTER TABLE `__new_users_table` RENAME TO `users_table`;--> statement-breakpoint+PRAGMA foreign_keys=ON;--> statement-breakpoint+CREATE UNIQUE INDEX `users_table_username_unique` ON `users_table` (`username`);\ No newline at end of filediff --git a/src/db/migrations/meta/0005_snapshot.json b/src/db/migrations/meta/0005_snapshot.jsonnew file mode 100644index 000000000..091c082f2--- /dev/null+++ b/src/db/migrations/meta/0005_snapshot.json@@ -0,0 +1,990 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "e352914b-cb67-42e1-952c-caebcf6e4548",+ "prevId": "780c2018-3df8-4c8f-bef6-2f332b639d9d",+ "tables": {+ "agent_tasks_table": {+ "name": "agent_tasks_table",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "payload": {+ "name": "payload",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "result": {+ "name": "result",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "error": {+ "name": "error",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "started_at": {+ "name": "started_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "completed_at": {+ "name": "completed_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "agent_tokens_table": {+ "name": "agent_tokens_table",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "permissions": {+ "name": "permissions",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'[]'"+ },+ "last_used": {+ "name": "last_used",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_active": {+ "name": "is_active",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {+ "agent_tokens_table_token_unique": {+ "name": "agent_tokens_table_token_unique",+ "columns": ["token"],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "agents_table": {+ "name": "agents_table",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "hostname": {+ "name": "hostname",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "platform": {+ "name": "platform",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "version": {+ "name": "version",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "capabilities": {+ "name": "capabilities",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'[]'"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'offline'"+ },+ "last_seen": {+ "name": "last_seen",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "registered_at": {+ "name": "registered_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "container_count": {+ "name": "container_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "image_count": {+ "name": "image_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "stack_count": {+ "name": "stack_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "network_count": {+ "name": "network_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "volume_count": {+ "name": "volume_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "docker_version": {+ "name": "docker_version",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "docker_containers": {+ "name": "docker_containers",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "docker_images": {+ "name": "docker_images",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "deployments_table": {+ "name": "deployments_table",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "task_id": {+ "name": "task_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "error": {+ "name": "error",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "image_maturity_table": {+ "name": "image_maturity_table",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "repository": {+ "name": "repository",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "tag": {+ "name": "tag",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "current_version": {+ "name": "current_version",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "latest_version": {+ "name": "latest_version",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'Unknown'"+ },+ "updates_available": {+ "name": "updates_available",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "current_image_date": {+ "name": "current_image_date",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "latest_image_date": {+ "name": "latest_image_date",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "days_since_creation": {+ "name": "days_since_creation",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "registry_domain": {+ "name": "registry_domain",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_private_registry": {+ "name": "is_private_registry",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "last_checked": {+ "name": "last_checked",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "check_count": {+ "name": "check_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 1+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "response_time_ms": {+ "name": "response_time_ms",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {+ "idx_image_maturity_repository": {+ "name": "idx_image_maturity_repository",+ "columns": ["repository"],+ "isUnique": false+ },+ "idx_image_maturity_status": {+ "name": "idx_image_maturity_status",+ "columns": ["status"],+ "isUnique": false+ },+ "idx_image_maturity_updates": {+ "name": "idx_image_maturity_updates",+ "columns": ["updates_available"],+ "isUnique": false+ },+ "idx_image_maturity_last_checked": {+ "name": "idx_image_maturity_last_checked",+ "columns": ["last_checked"],+ "isUnique": false+ },+ "idx_image_maturity_repo_tag": {+ "name": "idx_image_maturity_repo_tag",+ "columns": ["repository", "tag"],+ "isUnique": false+ },+ "idx_image_maturity_status_updates": {+ "name": "idx_image_maturity_status_updates",+ "columns": ["status", "updates_available"],+ "isUnique": false+ },+ "idx_image_maturity_registry": {+ "name": "idx_image_maturity_registry",+ "columns": ["registry_domain"],+ "isUnique": false+ },+ "idx_image_maturity_check_count": {+ "name": "idx_image_maturity_check_count",+ "columns": ["check_count"],+ "isUnique": false+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "settings_table": {+ "name": "settings_table",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": true+ },+ "dockerHost": {+ "name": "dockerHost",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "stacksDirectory": {+ "name": "stacksDirectory",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "autoUpdate": {+ "name": "autoUpdate",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "autoUpdateInterval": {+ "name": "autoUpdateInterval",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 300+ },+ "pollingEnabled": {+ "name": "pollingEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "pollingInterval": {+ "name": "pollingInterval",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 5+ },+ "pruneMode": {+ "name": "pruneMode",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "registryCredentials": {+ "name": "registryCredentials",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'[]'"+ },+ "templateRegistries": {+ "name": "templateRegistries",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'[]'"+ },+ "auth": {+ "name": "auth",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "onboarding": {+ "name": "onboarding",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "baseServerUrl": {+ "name": "baseServerUrl",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "maturityThresholdDays": {+ "name": "maturityThresholdDays",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 30+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updatedAt": {+ "name": "updatedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "stacks_table": {+ "name": "stacks_table",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "dir_name": {+ "name": "dir_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "path": {+ "name": "path",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "auto_update": {+ "name": "auto_update",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "is_external": {+ "name": "is_external",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "is_legacy": {+ "name": "is_legacy",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "is_remote": {+ "name": "is_remote",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "agent_hostname": {+ "name": "agent_hostname",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'unknown'"+ },+ "service_count": {+ "name": "service_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "running_count": {+ "name": "running_count",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "compose_content": {+ "name": "compose_content",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "env_content": {+ "name": "env_content",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_polled": {+ "name": "last_polled",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {+ "stacks_table_name_unique": {+ "name": "stacks_table_name_unique",+ "columns": ["name"],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "users_table": {+ "name": "users_table",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "username": {+ "name": "username",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "password_hash": {+ "name": "password_hash",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "display_name": {+ "name": "display_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "roles": {+ "name": "roles",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'[]'"+ },+ "require_password_change": {+ "name": "require_password_change",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "oidc_subject_id": {+ "name": "oidc_subject_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_login": {+ "name": "last_login",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch()"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "(unixepoch())"+ }+ },+ "indexes": {+ "users_table_username_unique": {+ "name": "users_table_username_unique",+ "columns": ["username"],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {}+ }+}diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.jsonindex af3fb85cc..7790aaa09 100644--- a/src/db/migrations/meta/_journal.json+++ b/src/db/migrations/meta/_journal.json@@ -1,41 +1,48 @@{- "version": "7",- "dialect": "sqlite",- "entries": [- {- "idx": 0,- "version": "6",- "when": 1748818742198,- "tag": "0000_short_wong",- "breakpoints": true- },- {- "idx": 1,- "version": "6",- "when": 1748827322259,- "tag": "0001_omniscient_captain_universe",- "breakpoints": true- },- {- "idx": 2,- "version": "6",- "when": 1748837434871,- "tag": "0002_chunky_silverclaw",- "breakpoints": true- },- {- "idx": 3,- "version": "6",- "when": 1748886756139,- "tag": "0003_typical_ogun",- "breakpoints": true- },- {- "idx": 4,- "version": "6",- "when": 1748889342137,- "tag": "0004_deep_meteorite",- "breakpoints": true- }- ]-}\ No newline at end of file+ "version": "7",+ "dialect": "sqlite",+ "entries": [+ {+ "idx": 0,+ "version": "6",+ "when": 1748818742198,+ "tag": "0000_short_wong",+ "breakpoints": true+ },+ {+ "idx": 1,+ "version": "6",+ "when": 1748827322259,+ "tag": "0001_omniscient_captain_universe",+ "breakpoints": true+ },+ {+ "idx": 2,+ "version": "6",+ "when": 1748837434871,+ "tag": "0002_chunky_silverclaw",+ "breakpoints": true+ },+ {+ "idx": 3,+ "version": "6",+ "when": 1748886756139,+ "tag": "0003_typical_ogun",+ "breakpoints": true+ },+ {+ "idx": 4,+ "version": "6",+ "when": 1748889342137,+ "tag": "0004_deep_meteorite",+ "breakpoints": true+ },+ {+ "idx": 5,+ "version": "6",+ "when": 1748988796406,+ "tag": "0005_aberrant_living_lightning",+ "breakpoints": true+ }+ ]+}diff --git a/src/db/schema.ts b/src/db/schema.tsindex c120f38cf..6ab8da97e 100644--- a/src/db/schema.ts+++ b/src/db/schema.ts@@ -1,4 +1,4 @@-import { int, sqliteTable, text, integer, real } from 'drizzle-orm/sqlite-core';+import { int, sqliteTable, text, integer, real, index } from 'drizzle-orm/sqlite-core';import { relations } from 'drizzle-orm';import { sql } from 'drizzle-orm';@@ -37,7 +37,7 @@ export const usersTable = sqliteTable('users_table', {lastLogin: int('last_login', { mode: 'timestamp' }),createdAt: int('created_at', { mode: 'timestamp' }).notNull()- .default(sql`(unixepoch())`),+ .default(sql`(unixepoch()`),updatedAt: int('updated_at', { mode: 'timestamp' }).notNull().default(sql`(unixepoch())`)@@ -171,6 +171,62 @@ export const deploymentsTable = sqliteTable('deployments_table', {.default(sql`(unixepoch())`)});+export const imageMaturityTable = sqliteTable(+ 'image_maturity_table',+ {+ id: text('id').primaryKey(), // This will be the image ID+ repository: text('repository').notNull(),+ tag: text('tag').notNull(),+ currentVersion: text('current_version').notNull(),+ latestVersion: text('latest_version'),+ status: text('status', { enum: ['Matured', 'Not Matured', 'Unknown'] })+ .notNull()+ .default('Unknown'),+ updatesAvailable: integer('updates_available', { mode: 'boolean' }).notNull().default(false),++ // Dates and timing+ currentImageDate: int('current_image_date', { mode: 'timestamp' }),+ latestImageDate: int('latest_image_date', { mode: 'timestamp' }),+ daysSinceCreation: int('days_since_creation'),++ // Registry information+ registryDomain: text('registry_domain'),+ isPrivateRegistry: integer('is_private_registry', { mode: 'boolean' }).notNull().default(false),++ // Check metadata+ lastChecked: int('last_checked', { mode: 'timestamp' }).notNull(),+ checkCount: int('check_count').notNull().default(1),+ lastError: text('last_error'),++ // Performance tracking+ responseTimeMs: int('response_time_ms'),++ createdAt: int('created_at', { mode: 'timestamp' })+ .notNull()+ .default(sql`(unixepoch())`),+ updatedAt: int('updated_at', { mode: 'timestamp' })+ .notNull()+ .default(sql`(unixepoch())`)+ },+ (table) => [+ // Single column indexes+ index('idx_image_maturity_repository').on(table.repository),+ index('idx_image_maturity_status').on(table.status),+ index('idx_image_maturity_updates').on(table.updatesAvailable),+ index('idx_image_maturity_last_checked').on(table.lastChecked),++ // Composite indexes for common query patterns+ index('idx_image_maturity_repo_tag').on(table.repository, table.tag),+ index('idx_image_maturity_status_updates').on(table.status, table.updatesAvailable),++ // Index for cleanup queries (registry domain filtering)+ index('idx_image_maturity_registry').on(table.registryDomain),++ // Index for performance monitoring+ index('idx_image_maturity_check_count').on(table.checkCount)+ ]+);+// Add foreign key relationships if you want referential integrity// Note: SQLite foreign keys need to be enabled at runtimeexport const agentRelations = {diff --git a/src/lib/components/maturity-item.svelte b/src/lib/components/maturity-item.svelteindex c8c5c6294..2fdb364b6 100644--- a/src/lib/components/maturity-item.svelte+++ b/src/lib/components/maturity-item.svelte@@ -1,6 +1,6 @@<script lang="ts">import * as Tooltip from '$lib/components/ui/tooltip/index.js';- import { CircleCheck, CircleFadingArrowUp, CircleArrowUp, Loader2 } from '@lucide/svelte';+ import { CircleCheck, CircleFadingArrowUp, CircleArrowUp, Loader2, Clock, Package, Calendar, AlertTriangle } from '@lucide/svelte';interface Props {maturity?:@@ -15,9 +15,66 @@}let { maturity = undefined, isLoadingInBackground = false }: Props = $props();++ // Helper function to format the date more nicely+ function formatDate(dateString: string | undefined): string {+ if (!dateString || dateString === 'Unknown date' || dateString === 'Invalid date') {+ return 'Unknown';+ }++ try {+ const date = new Date(dateString);+ if (isNaN(date.getTime())) return 'Unknown';++ const now = new Date();+ const diffTime = Math.abs(now.getTime() - date.getTime());+ const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));++ if (diffDays === 0) return 'Today';+ if (diffDays === 1) return 'Yesterday';+ if (diffDays < 7) return `${diffDays} days ago`;+ if (diffDays < 30) return `${Math.floor(diffDays / 7)} weeks ago`;+ if (diffDays < 365) return `${Math.floor(diffDays / 30)} months ago`;+ return `${Math.floor(diffDays / 365)} years ago`;+ } catch {+ return 'Unknown';+ }+ }++ // Helper function to get status color+ function getStatusColor(status: string): string {+ switch (status) {+ case 'Matured':+ return 'text-green-500';+ case 'Not Matured':+ return 'text-amber-500';+ case 'Unknown':+ return 'text-gray-500';+ default:+ return 'text-gray-500';+ }+ }++ // Helper function to get update priority level+ function getUpdatePriority(maturity: any): { level: string; color: string; description: string } {+ if (!maturity.updatesAvailable) {+ return { level: 'None', color: 'text-green-500', description: 'Image is up to date' };+ }++ if (maturity.status === 'Matured') {+ return { level: 'Recommended', color: 'text-blue-500', description: 'Stable update available' };+ }++ if (maturity.status === 'Not Matured') {+ return { level: 'Optional', color: 'text-yellow-500', description: 'Recent update, may be unstable' };+ }++ return { level: 'Unknown', color: 'text-gray-500', description: 'Update status unclear' };+ }</script>{#if maturity}+ {@const priority = getUpdatePriority(maturity)}<Tooltip.Provider><Tooltip.Root><Tooltip.Trigger>@@ -31,38 +88,86 @@{/if}</span></Tooltip.Trigger>- <Tooltip.Content side="right" class="p-3 max-w-[200px] relative tooltip-with-arrow" align="center">- <div class="space-y-2">- <div class="flex items-center gap-2">+ <Tooltip.Content side="right" class="bg-popover text-popover-foreground border border-border shadow-lg p-4 max-w-[280px] relative tooltip-with-arrow maturity-tooltip" align="center">+ <div class="space-y-3">+ <!-- Header with icon and status -->+ <div class="flex items-center gap-3 pb-2 border-b border-border">{#if !maturity.updatesAvailable}- <CircleCheck class="text-green-500 size-5" fill="none" stroke="currentColor" strokeWidth="2" />- <span class="font-medium">Image Up to Date</span>+ <div class="flex items-center justify-center w-8 h-8 rounded-full bg-green-500/10 border border-green-500/20">+ <CircleCheck class="text-green-500 size-5" fill="none" stroke="currentColor" strokeWidth="2" />+ </div>+ <div>+ <div class="font-semibold text-sm">Up to Date</div>+ <div class="text-xs text-muted-foreground">No updates available</div>+ </div>{:else if maturity.status === 'Not Matured'}- <CircleFadingArrowUp class="text-yellow-500 size-5" fill="none" stroke="currentColor" stroke-width="2" />- <span class="font-medium">Update Available (Not Matured)</span>+ <div class="flex items-center justify-center w-8 h-8 rounded-full bg-yellow-500/10 border border-yellow-500/20">+ <CircleFadingArrowUp class="text-yellow-500 size-5" fill="none" stroke="currentColor" stroke-width="2" />+ </div>+ <div>+ <div class="font-semibold text-sm">Update Available</div>+ <div class="text-xs text-yellow-600 dark:text-yellow-400 flex items-center gap-1">+ <AlertTriangle class="size-3" />+ Not yet matured+ </div>+ </div>{:else}- <CircleArrowUp class="text-blue-500 size-5" fill="none" stroke="currentColor" stroke-width="2" />- <span class="font-medium">Matured Update Available</span>+ <div class="flex items-center justify-center w-8 h-8 rounded-full bg-blue-500/10 border border-blue-500/20">+ <CircleArrowUp class="text-blue-500 size-5" fill="none" stroke="currentColor" stroke-width="2" />+ </div>+ <div>+ <div class="font-semibold text-sm">Stable Update</div>+ <div class="text-xs text-blue-600 dark:text-blue-400">Recommended for update</div>+ </div>{/if}</div>- <div class="pt-1 border-t border-gray-200 dark:border-gray-700 justify-between">- <div class="flex justify-between text-xs">- <span class="text-muted-foreground">Version:</span>- <span class="font-medium">{maturity.version || 'N/A'}</span>+ <!-- Details grid -->+ <div class="grid gap-2 text-xs">+ <div class="flex items-center justify-between">+ <div class="flex items-center gap-1.5 text-muted-foreground">+ <Package class="size-3" />+ <span>Version</span>+ </div>+ <span class="font-mono font-medium">{maturity.version || 'Unknown'}</span></div>- <div class="flex justify-between text-xs mt-1">- <span class="text-muted-foreground">Released:</span>- <span>{maturity.date || 'Unknown'}</span>+ <div class="flex items-center justify-between">+ <div class="flex items-center gap-1.5 text-muted-foreground">+ <Calendar class="size-3" />+ <span>Released</span>+ </div>+ <span class="font-medium">{formatDate(maturity.date)}</span></div>- <div class="flex justify-between text-xs mt-1">- <span class="text-muted-foreground">Status:</span>- <span class={maturity.status === 'Matured' ? 'text-green-500' : 'text-amber-500'}>+ <div class="flex items-center justify-between">+ <div class="flex items-center gap-1.5 text-muted-foreground">+ <Clock class="size-3" />+ <span>Status</span>+ </div>+ <span class="font-medium {getStatusColor(maturity.status)}">{maturity.status || 'Unknown'}</span></div>++ <div class="flex items-center justify-between">+ <div class="flex items-center gap-1.5 text-muted-foreground">+ <span>Priority</span>+ </div>+ <span class="font-medium {priority.color}">+ {priority.level}+ </span>+ </div>+ </div>++ <!-- Update recommendation -->+ <div class="pt-2 border-t border-border">+ <div class="text-xs text-muted-foreground leading-relaxed">+ {priority.description}+ </div>+ {#if maturity.updatesAvailable && maturity.status === 'Not Matured'}+ <div class="mt-1 text-xs text-amber-600 dark:text-amber-400 leading-relaxed">Consider waiting for the update to mature before upgrading.</div>+ {/if}</div></div></Tooltip.Content>@@ -76,8 +181,14 @@<Loader2 class="text-blue-400 size-4 animate-spin" /></span></Tooltip.Trigger>- <Tooltip.Content side="right" class="p-2 relative tooltip-with-arrow" align="center">- <span class="text-xs">Checking maturity status...</span>+ <Tooltip.Content side="right" class="bg-popover text-popover-foreground border border-border shadow-lg p-3 max-w-[220px] relative tooltip-with-arrow" align="center">+ <div class="flex items-center gap-2">+ <Loader2 class="text-blue-400 size-4 animate-spin" />+ <div>+ <div class="text-sm font-medium">Checking Updates</div>+ <div class="text-xs text-muted-foreground">Querying registry for latest version...</div>+ </div>+ </div></Tooltip.Content></Tooltip.Root></Tooltip.Provider>@@ -86,14 +197,21 @@<Tooltip.Root><Tooltip.Trigger><span class="inline-flex items-center justify-center mr-2 opacity-30 size-4">- <svg class="text-gray-500 size-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">- <circle cx="12" cy="12" r="10" />- <path d="M9 12l2 2 4-4" />- </svg>+ <div class="w-4 h-4 rounded-full border-2 border-gray-400 border-dashed flex items-center justify-center">+ <div class="w-1.5 h-1.5 bg-gray-400 rounded-full"></div>+ </div></span></Tooltip.Trigger>- <Tooltip.Content side="right" class="p-2 relative tooltip-with-arrow" align="center">- <span class="text-xs">Maturity status not available.</span>+ <Tooltip.Content side="right" class="bg-popover text-popover-foreground border border-border shadow-lg p-3 max-w-[240px] relative tooltip-with-arrow" align="center">+ <div class="flex items-center gap-2">+ <div class="flex items-center justify-center w-6 h-6 rounded-full bg-muted border border-border">+ <AlertTriangle class="text-muted-foreground size-3" />+ </div>+ <div>+ <div class="text-sm font-medium">Status Unknown</div>+ <div class="text-xs text-muted-foreground leading-relaxed">Unable to determine maturity status. Registry may be unavailable or rate-limited.</div>+ </div>+ </div></Tooltip.Content></Tooltip.Root></Tooltip.Provider>diff --git a/src/lib/components/ui/tooltip/tooltip-content.svelte b/src/lib/components/ui/tooltip/tooltip-content.svelteindex b0c399ca4..e10f38667 100644--- a/src/lib/components/ui/tooltip/tooltip-content.svelte+++ b/src/lib/components/ui/tooltip/tooltip-content.svelte@@ -1,12 +1,12 @@<script lang="ts">- import { Tooltip as TooltipPrimitive } from "bits-ui";- import { cn } from "$lib/utils.js";+ import { Tooltip as TooltipPrimitive } from 'bits-ui';+ import { cn } from '$lib/utils.js';let {ref = $bindable(null),class: className,sideOffset = 0,- side = "top",+ side = 'top',children,arrowClasses,...restProps@@ -22,7 +22,7 @@{sideOffset}{side}class={cn(- "bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--bits-tooltip-content-transform-origin) z-50 w-fit text-balance rounded-md px-3 py-1.5 text-xs",+ 'bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--bits-tooltip-content-transform-origin) z-50 w-fit text-balance rounded-md px-3 py-1.5 text-xs',className)}{...restProps}@@ -31,14 +31,7 @@<TooltipPrimitive.Arrow>{#snippet child({ props })}<div- class={cn(- "bg-primary z-50 size-2.5 rotate-45 rounded-[2px]",- "data-[side=top]:translate-x-1/2 data-[side=top]:translate-y-[calc(-50%_+_2px)]",- "data-[side=bottom]:-translate-y-[calc(-50%_+_1px)] data-[side=bottom]:translate-x-1/2",- "data-[side=right]:translate-x-[calc(50%_+_2px)] data-[side=right]:translate-y-1/2",- "data-[side=left]:translate-y-[calc(50%_-_3px)]",- arrowClasses- )}+ class={cn('bg-popover z-50 size-2.5 rotate-45 rounded-[2px]', 'data-[side=top]:translate-x-1/2 data-[side=top]:translate-y-[calc(-50%_+_2px)]', 'data-[side=bottom]:-translate-y-[calc(-50%_+_1px)] data-[side=bottom]:translate-x-1/2', 'data-[side=right]:translate-x-[calc(50%_+_2px)] data-[side=right]:translate-y-1/2', 'data-[side=left]:translate-y-[calc(50%_-_3px)]', arrowClasses)}{...props}></div>{/snippet}diff --git a/src/lib/services/database/image-maturity-db-service.ts b/src/lib/services/database/image-maturity-db-service.tsnew file mode 100644index 000000000..5cf2c790a--- /dev/null+++ b/src/lib/services/database/image-maturity-db-service.ts@@ -0,0 +1,297 @@+import { db } from '../../../db';+import { imageMaturityTable } from '../../../db/schema';+import { eq, lt, desc, asc, inArray, notInArray, sql } from 'drizzle-orm';+import type { ImageMaturity } from '$lib/types/docker/image.type';++export interface ImageMaturityRecord {+ id: string;+ repository: string;+ tag: string;+ currentVersion: string;+ latestVersion: string | null;+ status: 'Matured' | 'Not Matured' | 'Unknown';+ updatesAvailable: boolean;+ currentImageDate: Date | null;+ latestImageDate: Date | null;+ daysSinceCreation: number | null;+ registryDomain: string | null;+ isPrivateRegistry: boolean;+ lastChecked: Date;+ checkCount: number;+ lastError: string | null;+ responseTimeMs: number | null;+ createdAt: Date;+ updatedAt: Date;+}++export class ImageMaturityDbService {+ /**+ * Get maturity data for a single image+ */+ async getImageMaturity(imageId: string): Promise<ImageMaturityRecord | null> {+ const result = await db.select().from(imageMaturityTable).where(eq(imageMaturityTable.id, imageId)).limit(1);++ return result[0] || null;+ }++ /**+ * Get maturity data for multiple images+ */+ async getImageMaturityBatch(imageIds: string[]): Promise<Map<string, ImageMaturityRecord>> {+ const results = new Map<string, ImageMaturityRecord>();++ if (imageIds.length === 0) return results;++ const records = await db.select().from(imageMaturityTable).where(inArray(imageMaturityTable.id, imageIds));++ for (const record of records) {+ results.set(record.id, record);+ }++ return results;+ }++ /**+ * Store or update maturity data for an image+ */+ async setImageMaturity(+ imageId: string,+ repository: string,+ tag: string,+ maturity: ImageMaturity,+ metadata: {+ registryDomain?: string;+ isPrivateRegistry?: boolean;+ responseTimeMs?: number;+ error?: string;+ latestVersion?: string;+ } = {}+ ): Promise<void> {+ const now = new Date();++ // Parse dates from maturity data+ let currentImageDate: Date | null = null;+ let daysSince: number | null = null;++ if (maturity.date && maturity.date !== 'Unknown date' && maturity.date !== 'Invalid date') {+ try {+ currentImageDate = new Date(maturity.date);+ if (!isNaN(currentImageDate.getTime())) {+ daysSince = Math.floor((now.getTime() - currentImageDate.getTime()) / (1000 * 60 * 60 * 24));+ } else {+ currentImageDate = null;+ }+ } catch {+ currentImageDate = null;+ }+ }++ const baseData = {+ id: imageId,+ repository,+ tag,+ currentVersion: maturity.version,+ latestVersion: maturity.updatesAvailable ? metadata.latestVersion || null : null, // Fix: use actual latest version+ status: maturity.status,+ updatesAvailable: maturity.updatesAvailable,+ currentImageDate,+ latestImageDate: null, // Simplified: don't handle latest image date+ daysSinceCreation: daysSince,+ registryDomain: metadata.registryDomain || null,+ isPrivateRegistry: metadata.isPrivateRegistry || false,+ lastChecked: now,+ lastError: metadata.error || null,+ responseTimeMs: metadata.responseTimeMs || null,+ updatedAt: now+ };++ // Use upsert (INSERT ... ON CONFLICT) to handle race conditions atomically+ await db+ .insert(imageMaturityTable)+ .values({+ ...baseData,+ checkCount: 1,+ createdAt: now+ })+ .onConflictDoUpdate({+ target: imageMaturityTable.id,+ set: {+ ...baseData,+ checkCount: sql`${imageMaturityTable.checkCount} + 1`,+ // Don't update createdAt on conflict - keep original value+ createdAt: sql`${imageMaturityTable.createdAt}`+ }+ });+ }++ /**+ * Batch update multiple image maturity records+ */+ async setImageMaturityBatch(+ updates: Array<{+ imageId: string;+ repository: string;+ tag: string;+ maturity: ImageMaturity;+ metadata?: {+ registryDomain?: string;+ isPrivateRegistry?: boolean;+ responseTimeMs?: number;+ error?: string;+ latestVersion?: string; // Add this field+ };+ }>+ ): Promise<void> {+ if (updates.length === 0) return;++ // Process in batches to avoid SQL parameter limits+ const batchSize = 100;+ for (let i = 0; i < updates.length; i += batchSize) {+ const batch = updates.slice(i, i + batchSize);++ await Promise.all(batch.map(({ imageId, repository, tag, maturity, metadata }) => this.setImageMaturity(imageId, repository, tag, maturity, metadata || {})));+ }+ }++ /**+ * Get images that need maturity checking based on last check time+ */+ async getImagesNeedingCheck(maxAgeMinutes: number = 120, limit: number = 100): Promise<ImageMaturityRecord[]> {+ const cutoffTime = new Date(Date.now() - maxAgeMinutes * 60 * 1000);++ return await db.select().from(imageMaturityTable).where(lt(imageMaturityTable.lastChecked, cutoffTime)).orderBy(asc(imageMaturityTable.lastChecked)).limit(limit);+ }++ /**+ * Get images with available updates+ */+ async getImagesWithUpdates(): Promise<ImageMaturityRecord[]> {+ return await db.select().from(imageMaturityTable).where(eq(imageMaturityTable.updatesAvailable, true)).orderBy(desc(imageMaturityTable.lastChecked));+ }++ /**+ * Get images by repository+ */+ async getImagesByRepository(repository: string): Promise<ImageMaturityRecord[]> {+ return await db.select().from(imageMaturityTable).where(eq(imageMaturityTable.repository, repository)).orderBy(desc(imageMaturityTable.lastChecked));+ }++ /**+ * Delete maturity records for images that no longer exist+ */+ async cleanupOrphanedRecords(existingImageIds: string[]): Promise<number> {+ if (existingImageIds.length === 0) {+ // If no images exist, clean up everything+ const result = await db.delete(imageMaturityTable);+ return result.rowsAffected || 0;+ }++ // Use notInArray for cleaner syntax+ const result = await db.delete(imageMaturityTable).where(notInArray(imageMaturityTable.id, existingImageIds));++ return result.rowsAffected || 0;+ }++ /**+ * Clean up old records (older than specified days)+ */+ async cleanupOldRecords(daysOld: number = 30): Promise<number> {+ const cutoffTime = new Date(Date.now() - daysOld * 24 * 60 * 60 * 1000);++ const result = await db.delete(imageMaturityTable).where(lt(imageMaturityTable.lastChecked, cutoffTime));++ return result.rowsAffected || 0;+ }++ /**+ * Invalidate maturity records by setting lastChecked to an old date+ */+ async invalidateRecords(imageIds: string[]): Promise<number> {+ if (imageIds.length === 0) return 0;++ const oldDate = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000); // 7 days ago++ const result = await db+ .update(imageMaturityTable)+ .set({+ lastChecked: oldDate,+ updatedAt: new Date()+ })+ .where(inArray(imageMaturityTable.id, imageIds));++ return result.rowsAffected || 0;+ }++ /**+ * Invalidate maturity records for a specific repository+ */+ async invalidateRepository(repository: string): Promise<number> {+ const oldDate = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000); // 7 days ago++ const result = await db+ .update(imageMaturityTable)+ .set({+ lastChecked: oldDate,+ updatedAt: new Date()+ })+ .where(eq(imageMaturityTable.repository, repository));++ return result.rowsAffected || 0;+ }++ /**+ * Get maturity statistics+ */+ async getMaturityStats(): Promise<{+ total: number;+ withUpdates: number;+ matured: number;+ notMatured: number;+ unknown: number;+ averageAge: number;+ recentlyChecked: number;+ }> {+ const now = new Date();+ const oneHourAgo = new Date(now.getTime() - 60 * 60 * 1000);++ const oneHourAgoUnix = Math.floor(oneHourAgo.getTime() / 1000);++ const stats = await db+ .select({+ total: sql<number>`COUNT(*)`,+ withUpdates: sql<number>`SUM(CASE WHEN ${imageMaturityTable.updatesAvailable} = 1 THEN 1 ELSE 0 END)`,+ matured: sql<number>`SUM(CASE WHEN ${imageMaturityTable.status} = 'Matured' THEN 1 ELSE 0 END)`,+ notMatured: sql<number>`SUM(CASE WHEN ${imageMaturityTable.status} = 'Not Matured' THEN 1 ELSE 0 END)`,+ unknown: sql<number>`SUM(CASE WHEN ${imageMaturityTable.status} = 'Unknown' THEN 1 ELSE 0 END)`,+ avgDays: sql<number>`AVG(${imageMaturityTable.daysSinceCreation})`,+ recentlyChecked: sql<number>`SUM(CASE WHEN ${imageMaturityTable.lastChecked} > ${oneHourAgoUnix} THEN 1 ELSE 0 END)`+ })+ .from(imageMaturityTable);++ const result = stats[0];+ return {+ total: result.total || 0,+ withUpdates: result.withUpdates || 0,+ matured: result.matured || 0,+ notMatured: result.notMatured || 0,+ unknown: result.unknown || 0,+ averageAge: result.avgDays || 0,+ recentlyChecked: result.recentlyChecked || 0+ };+ }++ /**+ * Convert database record to ImageMaturity format for backward compatibility+ */+ recordToImageMaturity(record: ImageMaturityRecord): ImageMaturity {+ return {+ version: record.currentVersion,+ date: record.currentImageDate?.toLocaleDateString() || 'Unknown date',+ status: record.status,+ updatesAvailable: record.updatesAvailable+ };+ }+}++// Export singleton instance+export const imageMaturityDb = new ImageMaturityDbService();diff --git a/src/lib/services/docker/image-service.ts b/src/lib/services/docker/image-service.tsindex ccf62204c..4d1d082a0 100644--- a/src/lib/services/docker/image-service.ts+++ b/src/lib/services/docker/image-service.ts@@ -5,7 +5,7 @@ import { NotFoundError, DockerApiError, RegistryRateLimitError, PublicRegistryErimport { parseImageNameForRegistry, areRegistriesEquivalent } from '$lib/utils/registry.utils';import { getSettings } from '$lib/services/settings-service';import { tryCatch } from '$lib/utils/try-catch';-import { maturityCache, getImageMaturity, setImageMaturity, getImageMaturityBatch, setImageMaturityBatch } from './maturity-cache-service';+import { imageMaturityDb } from '../database/image-maturity-db-service';let maturityPollingInterval: NodeJS.Timeout | null = null;@@ -33,11 +33,11 @@ export async function initMaturityPollingScheduler(): Promise<void> {console.log(`Starting image maturity polling with interval of ${intervalMinutes} minutes`);- // Start background cleanup for the cache- maturityCache.startBackgroundCleanup(15); // Every 15 minutes-// Schedule regular checksmaturityPollingInterval = setInterval(runMaturityChecks, intervalMs);++ // Run initial check+ runMaturityChecks();}/**@@ -49,13 +49,10 @@ export async function stopMaturityPollingScheduler(): Promise<void> {maturityPollingInterval = null;console.log('Image maturity polling scheduler stopped');}-- // Stop background cleanup- maturityCache.stopBackgroundCleanup();}/**- * Run maturity checks for all images - OPTIMIZED VERSION+ * Run maturity checks for all images - DATABASE VERSION*/async function runMaturityChecks(): Promise<void> {console.log('Running scheduled image maturity checks...');@@ -67,8 +64,6 @@ async function runMaturityChecks(): Promise<void> {}const images = imagesResult.data;-- // Filter out images without proper tagsconst validImages = images.filter((image) => image.repo !== '<none>' && image.tag !== '<none>');console.log(`Found ${validImages.length} valid images to check maturity for`);@@ -78,87 +73,125 @@ async function runMaturityChecks(): Promise<void> {return;}- // Extract image IDs for batch processing- const imageIds = validImages.map((image) => image.Id);+ // Clean up orphaned records first+ const existingImageIds = validImages.map((img) => img.Id);+ const cleanedUp = await imageMaturityDb.cleanupOrphanedRecords(existingImageIds);+ if (cleanedUp > 0) {+ console.log(`Cleaned up ${cleanedUp} orphaned maturity records`);+ }- // Get cached maturity data in batch- const cachedMaturity = getImageMaturityBatch(imageIds);+ // Get images that need checking (haven't been checked recently)+ const settings = await getSettings();+ const checkIntervalMinutes = settings.pollingInterval || 120; // Default 2 hours- // Separate images that need checking vs those that are cached- const imagesToCheck: ServiceImage[] = [];- const cachedCount = cachedMaturity.size;+ const imagesToCheck = await imageMaturityDb.getImagesNeedingCheck(checkIntervalMinutes, 50);+ const imageIdsNeedingCheck = new Set(imagesToCheck.map((record) => record.id));+ // Add any images not in database yetfor (const image of validImages) {- if (!cachedMaturity.has(image.Id)) {- imagesToCheck.push(image);+ const existing = await imageMaturityDb.getImageMaturity(image.Id);+ if (!existing) {+ imageIdsNeedingCheck.add(image.Id);}}- console.log(`${cachedCount} images found in cache, ${imagesToCheck.length} need fresh checks`);+ const imagesToProcess = validImages.filter((img) => imageIdsNeedingCheck.has(img.Id));++ console.log(`${imagesToProcess.length} images need fresh maturity checks`);- if (imagesToCheck.length === 0) {- console.log('All images have cached maturity data, no fresh checks needed');+ if (imagesToProcess.length === 0) {+ console.log('All images have recent maturity data');return;}- // Process images in smaller batches to avoid overwhelming registries+ // Process images in batchesconst batchSize = 10;- const maturityUpdates = new Map<string, import('$lib/types/docker/image.type').ImageMaturity | undefined>();let checkedCount = 0;let updatesFound = 0;+ const updates: Array<{+ imageId: string;+ repository: string;+ tag: string;+ maturity: import('$lib/types/docker/image.type').ImageMaturity;+ metadata: any;+ }> = [];++ for (let i = 0; i < imagesToProcess.length; i += batchSize) {+ const batch = imagesToProcess.slice(i, i + batchSize);+ console.log(`Processing batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(imagesToProcess.length / batchSize)}: ${batch.length} images`);- for (let i = 0; i < imagesToCheck.length; i += batchSize) {- const batch = imagesToCheck.slice(i, i + batchSize);- console.log(`Processing batch ${Math.floor(i / batchSize) + 1}/${Math.ceil(imagesToCheck.length / batchSize)}: ${batch.length} images`);-- // Process batch with delay between each imagefor (const image of batch) {+ const startTime = Date.now();const maturityResult = await tryCatch(checkImageMaturityInternal(image.Id));+ const responseTime = Date.now() - startTime;if (!maturityResult.error && maturityResult.data) {- maturityUpdates.set(image.Id, maturityResult.data);+ updates.push({+ imageId: image.Id,+ repository: image.repo,+ tag: image.tag,+ maturity: maturityResult.data,+ metadata: {+ registryDomain: parseImageNameForRegistry(image.repo).registry,+ responseTimeMs: responseTime+ }+ });checkedCount++;if (maturityResult.data.updatesAvailable) {updatesFound++;}- } else if (!maturityResult.error) {- // No error but no data - cache the undefined result- maturityUpdates.set(image.Id, undefined);+ } else {+ // Store error information+ updates.push({+ imageId: image.Id,+ repository: image.repo,+ tag: image.tag,+ maturity: {+ version: image.tag,+ date: 'Unknown date',+ status: 'Unknown',+ updatesAvailable: false+ },+ metadata: {+ registryDomain: parseImageNameForRegistry(image.repo).registry,+ responseTimeMs: responseTime,+ error: maturityResult.error?.message || 'Unknown error'+ }+ });checkedCount++;}- // Small delay to avoid overwhelming registries+ // Small delay between checksawait new Promise((resolve) => setTimeout(resolve, 200));}- // Batch update cache after each batch- if (maturityUpdates.size > 0) {- setImageMaturityBatch(maturityUpdates);- maturityUpdates.clear();+ // Batch update database after each batch+ if (updates.length > 0) {+ await imageMaturityDb.setImageMaturityBatch(updates);+ updates.length = 0; // Clear the array}// Larger delay between batches- if (i + batchSize < imagesToCheck.length) {+ if (i + batchSize < imagesToProcess.length) {await new Promise((resolve) => setTimeout(resolve, 1000));}}- console.log(`Maturity check completed: Checked ${checkedCount} images, found ${updatesFound} updates, ${cachedCount} from cache`);+ console.log(`Maturity check completed: Checked ${checkedCount} images, found ${updatesFound} with updates`);- // Get cache metrics for monitoring- const metrics = maturityCache.getMetrics();- console.log(`Cache metrics: Hit rate ${(metrics.hitRate * 100).toFixed(1)}%, Size ${metrics.size}/${metrics.maxSize}, Avg age ${Math.round(metrics.averageAge / (1000 * 60))}min`);+ // Get and log statistics+ const stats = await imageMaturityDb.getMaturityStats();+ console.log(`Maturity stats: ${stats.total} total, ${stats.withUpdates} with updates, ${stats.recentlyChecked} recently checked`);// Emit an event that the UI can listen to for updatesif (typeof window !== 'undefined') {window.dispatchEvent(new CustomEvent('maturity-check-complete', {detail: {- checkedCount: checkedCount + cachedCount,+ checkedCount,updatesFound,- freshChecks: checkedCount,- cacheHits: cachedCount+ stats}}));@@ -347,60 +380,126 @@ export async function pullImage(imageRef: string, platform?: string, authConfig?/*** Checks if a newer version of an image is available in the registry- * and returns maturity information. OPTIMIZED for public API use.+ * and returns maturity information. Now uses database storage.*/export async function checkImageMaturity(imageId: string): Promise<import('$lib/types/docker/image.type').ImageMaturity | undefined> {- // Use the optimized cache getter- const cachedMaturity = getImageMaturity(imageId);- if (cachedMaturity !== undefined) {- return cachedMaturity;+ // Check database first+ const record = await imageMaturityDb.getImageMaturity(imageId);++ // If we have recent data (within last 2 hours), return it+ if (record) {+ const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000);+ if (record.lastChecked > twoHoursAgo) {+ return imageMaturityDb.recordToImageMaturity(record);+ }+ }++ // Otherwise, perform fresh check+ const imageDetails = await getImage(imageId);+ if (!imageDetails || !imageDetails.RepoTags?.[0]) {+ return undefined;}- // If not in cache, perform the check and cache the result+ const repoTag = imageDetails.RepoTags[0];+ const lastColon = repoTag.lastIndexOf(':');+ if (lastColon === -1) return undefined;++ const repository = repoTag.substring(0, lastColon);+ const tag = repoTag.substring(lastColon + 1);++ const startTime = Date.now();const maturity = await checkImageMaturityInternal(imageId);- setImageMaturity(imageId, maturity);+ const responseTime = Date.now() - startTime;++ if (maturity) {+ // Store in database+ await imageMaturityDb.setImageMaturity(imageId, repository, tag, maturity, {+ registryDomain: parseImageNameForRegistry(repository).registry,+ responseTimeMs: responseTime+ });+ }return maturity;}/**- * Batch check multiple images for maturity - NEW OPTIMIZED METHOD+ * Batch check multiple images for maturity - DATABASE VERSION*/export async function checkImageMaturityBatch(imageIds: string[]): Promise<Map<string, import('$lib/types/docker/image.type').ImageMaturity | undefined>> {- // Get cached results first- const cachedResults = getImageMaturityBatch(imageIds);+ const results = new Map<string, import('$lib/types/docker/image.type').ImageMaturity | undefined>();++ // Get existing records from database+ const records = await imageMaturityDb.getImageMaturityBatch(imageIds);+ const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000);- // Find images that need fresh checks- const uncachedIds = imageIds.filter((id) => !cachedResults.has(id));+ const imageIdsNeedingCheck: string[] = [];- if (uncachedIds.length === 0) {- return cachedResults;+ // Check which images have recent data+ for (const imageId of imageIds) {+ const record = records.get(imageId);+ if (record && record.lastChecked > twoHoursAgo) {+ results.set(imageId, imageMaturityDb.recordToImageMaturity(record));+ } else {+ imageIdsNeedingCheck.push(imageId);+ }}- // Process uncached images- const freshResults = new Map<string, import('$lib/types/docker/image.type').ImageMaturity | undefined>();+ // Fresh check for images without recent data+ if (imageIdsNeedingCheck.length > 0) {+ const updates: Array<{+ imageId: string;+ repository: string;+ tag: string;+ maturity: import('$lib/types/docker/image.type').ImageMaturity;+ metadata: any;+ }> = [];++ for (const imageId of imageIdsNeedingCheck) {+ try {+ const imageDetails = await getImage(imageId);+ if (!imageDetails || !imageDetails.RepoTags?.[0]) {+ continue;+ }- for (const imageId of uncachedIds) {- try {- const maturity = await checkImageMaturityInternal(imageId);- freshResults.set(imageId, maturity);- } catch (error) {- console.warn(`Failed to check maturity for image ${imageId}:`, error);- freshResults.set(imageId, undefined);- }+ const repoTag = imageDetails.RepoTags[0];+ const lastColon = repoTag.lastIndexOf(':');+ if (lastColon === -1) continue;++ const repository = repoTag.substring(0, lastColon);+ const tag = repoTag.substring(lastColon + 1);++ const startTime = Date.now();+ const maturity = await checkImageMaturityInternal(imageId);+ const responseTime = Date.now() - startTime;++ if (maturity) {+ results.set(imageId, maturity);+ updates.push({+ imageId,+ repository,+ tag,+ maturity,+ metadata: {+ registryDomain: parseImageNameForRegistry(repository).registry,+ responseTimeMs: responseTime+ }+ });+ }+ } catch (error) {+ console.warn(`Failed to check maturity for image ${imageId}:`, error);+ }- // Small delay between checks- await new Promise((resolve) => setTimeout(resolve, 100));- }+ // Small delay between checks+ await new Promise((resolve) => setTimeout(resolve, 100));+ }- // Batch update cache- if (freshResults.size > 0) {- setImageMaturityBatch(freshResults);+ // Batch update database+ if (updates.length > 0) {+ await imageMaturityDb.setImageMaturityBatch(updates);+ }}- // Combine cached and fresh results- const allResults = new Map([...cachedResults, ...freshResults]);- return allResults;+ return results;}/**@@ -454,30 +553,37 @@ async function checkImageMaturityInternal(imageId: string): Promise<import('$lib}/**- * Get cache metrics for monitoring+ * Get maturity statistics for monitoring+ */+export async function getMaturityStats() {+ return await imageMaturityDb.getMaturityStats();+}++/**+ * Get images with available updates*/-export function getMaturityCacheMetrics(): {- hitRate: number;- size: number;- maxSize: number;- oldestEntry: number;- averageAge: number;-} {- return maturityCache.getMetrics();+export async function getImagesWithUpdates() {+ const records = await imageMaturityDb.getImagesWithUpdates();+ return records.map((record) => ({+ imageId: record.id,+ repository: record.repository,+ tag: record.tag,+ maturity: imageMaturityDb.recordToImageMaturity(record)+ }));}/**- * Invalidate maturity cache for a specific repository+ * Invalidate maturity data for a specific repository*/-export function invalidateRepositoryMaturity(repository: string): number {- return maturityCache.invalidateRepository(repository);+export async function invalidateRepositoryMaturity(repository: string): Promise<number> {+ return await imageMaturityDb.invalidateRepository(repository);}/**- * Clear all maturity cache data+ * Clear all maturity data*/-export function clearMaturityCache(): void {- maturityCache.clear();+export async function clearMaturityCache(): Promise<void> {+ await imageMaturityDb.cleanupOldRecords(0); // Remove all records}/**diff --git a/src/lib/services/docker/maturity-cache-service.ts b/src/lib/services/docker/maturity-cache-service.tsdeleted file mode 100644index ffb2f0024..000000000--- a/src/lib/services/docker/maturity-cache-service.ts+++ /dev/null@@ -1,396 +0,0 @@-import type { ImageMaturity } from '$lib/types/docker/image.type';-import { maturityStore, updateImageMaturity } from '$lib/stores/maturity-store';-import { get } from 'svelte/store';--interface CacheNode {- key: string;- data: ImageMaturity | undefined;- timestamp: number;- prev: CacheNode | null;- next: CacheNode | null;-}--export class MaturityCache {- private cache: Map<string, CacheNode> = new Map();- private head: CacheNode | null = null;- private tail: CacheNode | null = null;- private maxEntries: number = 100;- private ttlMs: number = 30 * 60 * 1000;- private hits = 0;- private misses = 0;-- constructor(options?: { maxEntries?: number; ttlMinutes?: number }) {- if (options?.maxEntries) this.maxEntries = options.maxEntries;- if (options?.ttlMinutes) this.ttlMs = options.ttlMinutes * 60 * 1000;-- // Initialize from existing store- this.initFromStore();- }-- // Get a value from cache - O(1) operation- get(imageId: string): ImageMaturity | undefined {- const node = this.cache.get(imageId);- if (!node) {- this.misses++;- return undefined;- }-- // Check if expired- if (Date.now() - node.timestamp > this.ttlMs) {- this.delete(imageId);- this.misses++;- return undefined;- }-- // Move to head (most recently used) - O(1) operation- this.hits++;- this.moveToHead(node);- return node.data;- }-- // Add or update a value - O(1) operation- set(imageId: string, data: ImageMaturity | undefined): void {- const existingNode = this.cache.get(imageId);-- if (existingNode) {- // Update existing node- existingNode.data = data;- existingNode.timestamp = Date.now();- this.moveToHead(existingNode);- } else {- // Create new node- const newNode: CacheNode = {- key: imageId,- data,- timestamp: Date.now(),- prev: null,- next: null- };-- // Remove least recently used if at capacity- if (this.cache.size >= this.maxEntries) {- this.removeTail();- }-- // Add to head- this.addToHead(newNode);- this.cache.set(imageId, newNode);- }-- // Update store only when necessary (debounced)- this.debouncedStoreUpdate(imageId, data);- }-- // O(1) removal- delete(imageId: string): void {- const node = this.cache.get(imageId);- if (!node) return;-- this.removeNode(node);- this.cache.delete(imageId);- this.debouncedStoreUpdate(imageId, undefined);- }-- // Efficient LRU operations- private addToHead(node: CacheNode): void {- node.prev = null;- node.next = this.head;-- if (this.head) {- this.head.prev = node;- }-- this.head = node;-- if (!this.tail) {- this.tail = node;- }- }-- private removeNode(node: CacheNode): void {- if (node.prev) {- node.prev.next = node.next;- } else {- this.head = node.next || null;- }-- if (node.next) {- node.next.prev = node.prev;- } else {- this.tail = node.prev || null;- }- }-- private moveToHead(node: CacheNode): void {- this.removeNode(node);- this.addToHead(node);- }-- private removeTail(): void {- if (!this.tail) return;-- const lastNode = this.tail;- this.removeNode(lastNode);- this.cache.delete(lastNode.key);- }-- // Debounced store updates to avoid excessive writes- private storeUpdateTimeouts = new Map<string, NodeJS.Timeout>();-- private debouncedStoreUpdate(imageId: string, data: ImageMaturity | undefined): void {- // Clear existing timeout- const existingTimeout = this.storeUpdateTimeouts.get(imageId);- if (existingTimeout) {- clearTimeout(existingTimeout);- }-- // Set new timeout- const timeout = setTimeout(() => {- updateImageMaturity(imageId, data);- this.storeUpdateTimeouts.delete(imageId);- }, 100); // 100ms debounce-- this.storeUpdateTimeouts.set(imageId, timeout);- }-- // Initialize cache from maturity store- private async initFromStore(): Promise<void> {- try {- const storeData = get(maturityStore);-- if (!storeData.maturityData) return;-- // Convert to array and sort by priority/usage- const entries = Object.entries(storeData.maturityData)- .filter(([_, maturity]) => maturity !== undefined)- .slice(0, this.maxEntries); // Limit from start-- // Initialize in chunks to avoid blocking- const chunkSize = 50;- for (let i = 0; i < entries.length; i += chunkSize) {- const chunk = entries.slice(i, i + chunkSize);-- // Process chunk- for (const [imageId, maturity] of chunk) {- const node: CacheNode = {- key: imageId,- data: maturity,- timestamp: storeData.lastChecked?.getTime() || Date.now(),- prev: null,- next: null- };-- this.cache.set(imageId, node);- this.addToHead(node);- }-- // Yield control to event loop- if (i + chunkSize < entries.length) {- await new Promise((resolve) => setTimeout(resolve, 0));- }- }- } catch (error) {- console.warn('Failed to initialize maturity cache from store:', error);- }- }-- // Clear all items from cache- clear(): void {- this.cache.clear();- this.head = null;- this.tail = null;- }-- // Get cache stats- getStats(): { size: number; maxSize: number } {- return {- size: this.cache.size,- maxSize: this.maxEntries- };- }-- // Batch get multiple entries- getBatch(imageIds: string[]): Map<string, ImageMaturity | undefined> {- const results = new Map<string, ImageMaturity | undefined>();- const now = Date.now();-- for (const imageId of imageIds) {- const node = this.cache.get(imageId);- if (node && now - node.timestamp <= this.ttlMs) {- results.set(imageId, node.data);- // Move to head without individual operations- this.moveToHead(node);- }- }-- return results;- }-- // Batch set multiple entries- setBatch(entries: Map<string, ImageMaturity | undefined>): void {- const updates: Array<[string, ImageMaturity | undefined]> = [];-- for (const [imageId, data] of entries) {- const existingNode = this.cache.get(imageId);-- if (existingNode) {- existingNode.data = data;- existingNode.timestamp = Date.now();- this.moveToHead(existingNode);- } else {- if (this.cache.size >= this.maxEntries) {- this.removeTail();- }-- const newNode: CacheNode = {- key: imageId,- data,- timestamp: Date.now(),- prev: null,- next: null- };-- this.addToHead(newNode);- this.cache.set(imageId, newNode);- }-- updates.push([imageId, data]);- }-- // Batch update store- this.batchStoreUpdate(updates);- }-- private batchStoreUpdate(updates: Array<[string, ImageMaturity | undefined]>): void {- // Group updates and send as single operation- setTimeout(() => {- for (const [imageId, data] of updates) {- updateImageMaturity(imageId, data);- }- }, 50);- }-- // Background cleanup of expired entries- private cleanupInterval: NodeJS.Timeout | null = null;-- startBackgroundCleanup(intervalMinutes = 10): void {- if (this.cleanupInterval) return;-- this.cleanupInterval = setInterval(- () => {- this.cleanupExpired();- },- intervalMinutes * 60 * 1000- );- }-- stopBackgroundCleanup(): void {- if (this.cleanupInterval) {- clearInterval(this.cleanupInterval);- this.cleanupInterval = null;- }- }-- private cleanupExpired(): void {- const now = Date.now();- const expiredKeys: string[] = [];-- // Walk from tail (oldest) to head- let current = this.tail;- while (current) {- if (now - current.timestamp > this.ttlMs) {- expiredKeys.push(current.key);- current = current.prev;- } else {- // Since we're walking from oldest to newest,- // we can break early when we find a non-expired entry- break;- }- }-- // Remove expired entries- for (const key of expiredKeys) {- this.delete(key);- }-- console.log(`Cleaned up ${expiredKeys.length} expired maturity cache entries`);- }-- // Add cache invalidation strategies- invalidatePattern(pattern: RegExp): number {- let invalidatedCount = 0;- const keysToDelete: string[] = [];-- for (const [key] of this.cache) {- if (pattern.test(key)) {- keysToDelete.push(key);- }- }-- for (const key of keysToDelete) {- this.delete(key);- invalidatedCount++;- }-- return invalidatedCount;- }-- invalidateRepository(repository: string): number {- const pattern = new RegExp(`^${repository.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`);- return this.invalidatePattern(pattern);- }-- // Get cache efficiency metrics- getMetrics(): {- hitRate: number;- size: number;- maxSize: number;- oldestEntry: number;- averageAge: number;- } {- if (this.cache.size === 0) {- return {- hitRate: 0,- size: 0,- maxSize: this.maxEntries,- oldestEntry: 0,- averageAge: 0- };- }-- const now = Date.now();- let totalAge = 0;- let oldestEntry = now;-- for (const [_, node] of this.cache) {- const age = now - node.timestamp;- totalAge += age;- if (node.timestamp < oldestEntry) {- oldestEntry = node.timestamp;- }- }-- return {- hitRate: this.hits / Math.max(this.hits + this.misses, 1),- size: this.cache.size,- maxSize: this.maxEntries,- oldestEntry: now - oldestEntry,- averageAge: totalAge / this.cache.size- };- }-}--// Create optimized singleton-export const maturityCache = new MaturityCache({- maxEntries: 500, // Increased for better hit rate- ttlMinutes: 120 // 2 hours for better persistence-});--// Start background cleanup-maturityCache.startBackgroundCleanup(15); // Every 15 minutes--// Export convenience functions-export const getImageMaturity = (imageId: string) => maturityCache.get(imageId);-export const setImageMaturity = (imageId: string, maturity: ImageMaturity | undefined) => maturityCache.set(imageId, maturity);-export const getImageMaturityBatch = (imageIds: string[]) => maturityCache.getBatch(imageIds);-export const setImageMaturityBatch = (entries: Map<string, ImageMaturity | undefined>) => maturityCache.setBatch(entries);diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.tsindex 560176716..f98c01e63 100644--- a/src/routes/+page.server.ts+++ b/src/routes/+page.server.ts@@ -3,7 +3,7 @@ import { listContainers } from '$lib/services/docker/container-service';import { getDockerInfo } from '$lib/services/docker/core';import { isImageInUse, listImages, checkImageMaturity } from '$lib/services/docker/image-service';import { getSettings } from '$lib/services/settings-service';-import { maturityCache } from '$lib/services/docker/maturity-cache-service';+import { imageMaturityDb } from '$lib/services/database/image-maturity-db-service';import type { EnhancedImageInfo, ServiceImage } from '$lib/types/docker';import type { ContainerInfo } from 'dockerode';@@ -43,9 +43,9 @@ export const load: PageServerLoad = async (): Promise<DashboardData> => {imagesData.map(async (image): Promise<EnhancedImageInfo> => {const inUse = await isImageInUse(image.Id);- const cachedMaturity = maturityCache.get(image.Id);+ const record = await imageMaturityDb.getImageMaturity(image.Id);+ let maturity = record ? imageMaturityDb.recordToImageMaturity(record) : undefined;- let maturity = cachedMaturity;if (maturity === undefined) {try {if (image.repo !== '<none>' && image.tag !== '<none>') {diff --git a/src/routes/api/images/[id]/maturity/+server.ts b/src/routes/api/images/[id]/maturity/+server.tsindex 85c47aca5..be6cffa74 100644--- a/src/routes/api/images/[id]/maturity/+server.ts+++ b/src/routes/api/images/[id]/maturity/+server.ts@@ -1,6 +1,7 @@import { json } from '@sveltejs/kit';import type { RequestHandler } from './$types';-import { checkImageMaturity } from '$lib/services/docker/image-service';+import { checkImageMaturity, checkImageMaturityBatch } from '$lib/services/docker/image-service';+import { imageMaturityDb } from '$lib/services/database/image-maturity-db-service';import { ApiErrorCode, type ApiErrorResponse } from '$lib/types/errors.type';import { extractDockerErrorMessage } from '$lib/utils/errors.util';import { tryCatch } from '$lib/utils/try-catch';@@ -19,74 +20,30 @@ export const POST: RequestHandler = async ({ request }) => {}try {- // Server-side promise pool with concurrency limit- const concurrencyLimit = 5; // Process 5 images at a time- const results: Record<string, any> = {};- const pending = new Set();- const errors: Record<string, string> = {};-- // Create a queue from all images that need checking- const queue = [...imageIds];-- // Process queue with limited concurrency- while (queue.length > 0 || pending.size > 0) {- // Fill up the pending set until we reach the concurrency limit- while (pending.size < concurrencyLimit && queue.length > 0) {- const imageId = queue.shift();- if (!imageId) continue;-- // Create the promise for this image check- const promise = (async () => {- try {- console.log(`Server: Checking maturity for image ${imageId}`);- const checkResult = await tryCatch(checkImageMaturity(imageId));-- if (checkResult.error) {- return {- imageId,- success: false,- error: extractDockerErrorMessage(checkResult.error)- };- }-- return { imageId, success: true, data: checkResult.data };- } catch (error) {- console.error(`Server: Failed to check maturity for ${imageId}:`, error);- return {- imageId,- success: false,- error: error instanceof Error ? error.message : 'Unknown error'- };- }- })();-- // Add to pending set and set up cleanup when done- pending.add(promise);- promise.then((result) => {- pending.delete(promise);-- if (result.success) {- results[result.imageId] = result.data;- } else {- errors[result.imageId] = result.error ?? 'Unknown error';- }- });- }+ console.log(`Server: Starting batch maturity check for ${imageIds.length} images`);- // Wait for at least one promise to resolve before continuing- if (pending.size >= concurrencyLimit || (queue.length === 0 && pending.size > 0)) {- await Promise.race(Array.from(pending));+ const results = await checkImageMaturityBatch(imageIds);+ const errors: Record<string, string> = {};+ const successResults: Record<string, any> = {};++ let successCount = 0;+ let failCount = 0;++ for (const [imageId, maturity] of results) {+ if (maturity) {+ successResults[imageId] = maturity;+ successCount++;+ } else {+ errors[imageId] = 'No maturity data available';+ failCount++;}}- const successCount = Object.keys(results).length;- const failCount = Object.keys(errors).length;-- console.log(`Server: Maturity check completed. ${successCount} successful, ${failCount} failed`);+ console.log(`Server: Batch maturity check completed. ${successCount} successful, ${failCount} failed`);return json({success: true,- results,+ results: successResults,errors,stats: {total: imageIds.length,@@ -119,22 +76,51 @@ export const GET: RequestHandler = async ({ params }) => {return json(response, { status: 400 });}- const result = await tryCatch(checkImageMaturity(id));+ try {+ const result = await checkImageMaturity(id);++ if (!result) {+ const response: ApiErrorResponse = {+ success: false,+ error: 'No maturity data available for this image',+ code: ApiErrorCode.NOT_FOUND+ };+ return json(response, { status: 404 });+ }- if (result.error) {- console.error('Error checking image maturity:', result.error);+ return json({+ success: true,+ result+ });+ } catch (error) {+ console.error('Error checking image maturity:', error);const response: ApiErrorResponse = {success: false,- error: extractDockerErrorMessage(result.error),+ error: extractDockerErrorMessage(error),code: ApiErrorCode.DOCKER_API_ERROR,- details: result.error+ details: error};return json(response, { status: 500 });}+};- return json({- success: true,- result- });+// New endpoint for getting maturity statistics+export const OPTIONS: RequestHandler = async () => {+ try {+ const stats = await imageMaturityDb.getMaturityStats();+ return json({+ success: true,+ stats+ });+ } catch (error) {+ console.error('Error getting maturity stats:', error);+ return json(+ {+ success: false,+ error: 'Failed to get maturity statistics'+ },+ { status: 500 }+ );+ }};diff --git a/src/routes/api/images/maturity/+server.ts b/src/routes/api/images/maturity/+server.tsnew file mode 100644index 000000000..dd78d2f25--- /dev/null+++ b/src/routes/api/images/maturity/+server.ts@@ -0,0 +1,123 @@+import { json } from '@sveltejs/kit';+import type { RequestHandler } from './$types';+import { listImages } from '$lib/services/docker/image-service';+import { imageMaturityDb } from '$lib/services/database/image-maturity-db-service';+import { checkImageMaturityBatch } from '$lib/services/docker/image-service';+import { ApiErrorCode, type ApiErrorResponse } from '$lib/types/errors.type';+import { tryCatch } from '$lib/utils/try-catch';++export const POST: RequestHandler = async ({ request }) => {+ try {+ const body = await request.json().catch(() => ({}));+ const { force = false } = body; // Force check even if recently checked++ console.log('Manual maturity check triggered', { force });++ // Get all images+ const imagesResult = await tryCatch(listImages());+ if (imagesResult.error) {+ const response: ApiErrorResponse = {+ success: false,+ error: 'Failed to list Docker images',+ code: ApiErrorCode.DOCKER_API_ERROR,+ details: imagesResult.error+ };+ return json(response, { status: 500 });+ }++ const images = imagesResult.data;+ const validImages = images.filter((image) => image.repo !== '<none>' && image.tag !== '<none>');++ if (validImages.length === 0) {+ return json({+ success: true,+ message: 'No valid images found to check',+ stats: { total: 0, checked: 0, updated: 0 }+ });+ }++ const imageIds = validImages.map((img) => img.Id);+ let imageIdsToCheck = imageIds;++ // If not forcing, only check images that need checking+ if (!force) {+ const imagesToCheck = await imageMaturityDb.getImagesNeedingCheck(120, 1000); // 2 hours, up to 1000 images+ const imageIdsNeedingCheck = new Set(imagesToCheck.map((record) => record.id));++ // FIXED: Use single batch query instead of N+1 queries+ const existingMaturityRecords = await imageMaturityDb.getImageMaturityBatch(imageIds);++ // Add any images not in database yet to the checking set+ for (const imageId of imageIds) {+ if (!existingMaturityRecords.has(imageId)) {+ imageIdsNeedingCheck.add(imageId);+ }+ }++ imageIdsToCheck = imageIds.filter((id) => imageIdsNeedingCheck.has(id));+ }++ console.log(`Checking maturity for ${imageIdsToCheck.length} of ${imageIds.length} images`);++ // Process in batches+ const batchSize = 20;+ let totalChecked = 0;+ let totalUpdated = 0;++ for (let i = 0; i < imageIdsToCheck.length; i += batchSize) {+ const batch = imageIdsToCheck.slice(i, i + batchSize);+ const results = await checkImageMaturityBatch(batch);++ totalChecked += batch.length;+ totalUpdated += Array.from(results.values()).filter((maturity) => maturity?.updatesAvailable).length;++ // Small delay between batches+ if (i + batchSize < imageIdsToCheck.length) {+ await new Promise((resolve) => setTimeout(resolve, 500));+ }+ }++ // Get final stats+ const stats = await imageMaturityDb.getMaturityStats();++ return json({+ success: true,+ message: `Checked ${totalChecked} images, found ${totalUpdated} with updates`,+ stats: {+ ...stats,+ total: imageIds.length,+ checked: totalChecked,+ updated: totalUpdated+ }+ });+ } catch (error) {+ console.error('Error in manual maturity check:', error);++ const response: ApiErrorResponse = {+ success: false,+ error: error instanceof Error ? error.message : 'Unknown error occurred',+ code: ApiErrorCode.INTERNAL_SERVER_ERROR,+ details: error+ };+ return json(response, { status: 500 });+ }+};++export const GET: RequestHandler = async () => {+ try {+ const stats = await imageMaturityDb.getMaturityStats();+ return json({+ success: true,+ stats+ });+ } catch (error) {+ console.error('Error getting maturity stats:', error);+ return json(+ {+ success: false,+ error: 'Failed to get maturity statistics'+ },+ { status: 500 }+ );+ }+};diff --git a/src/routes/images/+page.svelte b/src/routes/images/+page.svelteindex 14fd8602e..1831e5027 100644--- a/src/routes/images/+page.svelte+++ b/src/routes/images/+page.svelte@@ -3,7 +3,7 @@import type { EnhancedImageInfo } from '$lib/types/docker';import UniversalTable from '$lib/components/universal-table.svelte';import { Button } from '$lib/components/ui/button/index.js';- import { Download, AlertCircle, HardDrive, Trash2, Loader2, ChevronDown, CopyX, Ellipsis, ScanSearch, Funnel } from '@lucide/svelte';+ import { Download, AlertCircle, HardDrive, Trash2, Loader2, ChevronDown, CopyX, Ellipsis, ScanSearch, Funnel, RefreshCw } from '@lucide/svelte';import * as Alert from '$lib/components/ui/alert/index.js';import * as Card from '$lib/components/ui/card/index.js';import { goto, invalidateAll } from '$app/navigation';@@ -282,64 +282,29 @@});}- async function checkAllMaturity() {+ async function triggerManualMaturityCheck(force = false) {isLoading.checking = true;-- const imageIdsToCheck = images.filter((image) => image.Id).map((image) => image.Id);-- if (imageIdsToCheck.length === 0) {- toast.info('No images to check for updates.');- isLoading.checking = false;- return;- }-- console.log(`Client: Attempting to check maturity for ${imageIdsToCheck.length} images.`);-try {- const batchResult = await imageApi.checkMaturityBatch(imageIdsToCheck);-- if (!batchResult || typeof batchResult.success !== 'boolean') {- toast.error('Maturity check failed: Invalid response from server.');- isLoading.checking = false;- return;- }-- const stats = batchResult.stats || { total: 0, success: 0, failed: 0 };- const numSuccessfullyUpdated = stats.success || 0;- const numFailedByBackend = stats.failed || 0;- const numAttemptedByBackend = stats.total || numSuccessfullyUpdated + numFailedByBackend;-- console.log(`Backend Response: Attempted to process ${numAttemptedByBackend}, Succeeded (updated) ${numSuccessfullyUpdated}, Failed ${numFailedByBackend}.`);-- if (batchResult.success) {- if (numSuccessfullyUpdated > 0) {- toast.success(`Successfully retrieved updates for ${numSuccessfullyUpdated} image(s).`);- }- if (numFailedByBackend > 0) {- toast.warning(`Backend failed to check updates for ${numFailedByBackend} image(s).`);- }+ const response = await fetch('/api/images/maturity', {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ force })+ });- if (imageIdsToCheck.length > numAttemptedByBackend && numAttemptedByBackend >= 0) {- const notAttemptedCount = imageIdsToCheck.length - numAttemptedByBackend;- toast.info(`Server processed ${numAttemptedByBackend} of ${imageIdsToCheck.length} images. ${notAttemptedCount} were not processed by the backend.`);- } else if (numAttemptedByBackend > numSuccessfullyUpdated + numFailedByBackend) {- const processedWithoutUpdate = numAttemptedByBackend - (numSuccessfullyUpdated + numFailedByBackend);- if (processedWithoutUpdate > 0) {- toast.info(`${processedWithoutUpdate} image(s) were checked by the backend but had no new update status reported.`);- }- }+ const result = await response.json();- if (numSuccessfullyUpdated === 0 && numFailedByBackend === 0 && numAttemptedByBackend === 0 && imageIdsToCheck.length > 0) {- toast.info('Maturity check ran, but the backend reported no images were processed or updated.');+ if (result.success) {+ toast.success(result.message);+ if (result.stats) {+ console.log('Maturity check stats:', result.stats);}-await invalidateAll();} else {- toast.error(`Maturity check request failed: ${batchResult.error || 'Unknown server error.'}`);+ toast.error(`Manual check failed: ${result.error}`);}} catch (error) {- console.error('Client-side error during checkAllMaturity:', error);- toast.error(`Client-side error checking image updates: ${(error as Error).message}`);+ console.error('Manual maturity check error:', error);+ toast.error('Failed to trigger manual maturity check');} finally {isLoading.checking = false;}@@ -467,7 +432,7 @@{/if}<ArcaneButton action="remove" label="Prune Unused" onClick={() => (isConfirmPruneDialogOpen = true)} loading={isLoading.pruning} loadingLabel="Pruning..." disabled={isLoading.pruning} /><ArcaneButton action="pull" label="Pull Image" onClick={() => (isPullDialogOpen = true)} loading={isLoading.pulling} loadingLabel="Pulling..." disabled={isLoading.pulling} />- <ArcaneButton action="inspect" label="Check Updates" onClick={() => checkAllMaturity()} loading={isLoading.checking} loadingLabel="Checking..." disabled={isLoading.checking} />+ <ArcaneButton action="inspect" label="Check Updates" onClick={() => triggerManualMaturityCheck(true)} loading={isLoading.checking} loadingLabel="Checking..." disabled={isLoading.checking} /></div></div></Card.Header>