getStorageStats method

  1. @override
Future<Map<String, int>> getStorageStats()
override

Gets storage statistics

Implementation

@override
Future<Map<String, int>> getStorageStats() async {
  await _ensureInitialized();

  try {
    final stats = <String, int>{};

    // Get protected files
    final protectedFiles = await ModelPreferencesManager.getAllProtectedFiles();
    stats['protectedFiles'] = protectedFiles.length;

    // Calculate total size of protected files
    int totalSize = 0;
    for (final filename in protectedFiles) {
      final path = await ModelFileSystemManager.getModelFilePath(filename);
      totalSize += await ModelFileSystemManager.getFileSize(path);
    }
    stats['totalSizeBytes'] = totalSize;
    stats['totalSizeMB'] = (totalSize / (1024 * 1024)).round();

    // Get counts by type
    final inferenceFiles = await ModelPreferencesManager.getInstalledFiles(ModelManagementType.inference);
    final embeddingFiles = await ModelPreferencesManager.getInstalledFiles(ModelManagementType.embedding);

    stats['inferenceModels'] = inferenceFiles.length;
    stats['embeddingModels'] = embeddingFiles.length ~/ 2; // Each embedding model has 2 files

    return stats;
  } catch (e) {
    debugPrint('UnifiedModelManager: Failed to get storage stats: $e');
    return {
      'protectedFiles': 0,
      'totalSizeBytes': 0,
      'totalSizeMB': 0,
      'inferenceModels': 0,
      'embeddingModels': 0,
    };
  }
}