Skip to content

[Enhancement] ProcessSnapshotProvider 实例重建时 metadataCache 全量失效 #11

@ShadyUnderLight

Description

@ShadyUnderLight

问题描述

ProcessSnapshotProvidermetadataCache 是实例变量。如果 MonitorViewModel 重建了 ProcessSnapshotProvider(如 app 重启某些阶段、settings 变更触发 reload),之前缓存的所有进程 metadata(appName、bundleIdentifier)全部丢失。

metadataRefreshInterval 默认 30 秒,同一台机器上进程 metadata 在 app 生命周期内变化极少,但每次 app 重启都重新走一遍 NSRunningApplication 全量查询,浪费。

预期结果

metadataCache 持久化,不随 ProcessSnapshotProvider 实例销毁而丢失。

建议方案

  1. ProcessSnapshotProvider 本身设计为 singleton actor(或通过 DI container 管理单例)
  2. 或者将 metadataCache 提取为独立 persistent actor,生命周期与 app 对齐
  3. 快速方案:ProcessSnapshotProvider 增加 init(existingCache: ...) 支持注入已有 cache

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions