Optimize multi-repo detection: use lightweight database check, avoid network fetches
Co-authored-by: Nandanrmenon <16499541+Nandanrmenon@users.noreply.github.com>
This commit is contained in:
co-authored by
Nandanrmenon
parent
586715769d
commit
e2cd3caa1e
@@ -220,6 +220,7 @@ class AppProvider extends ChangeNotifier {
|
||||
|
||||
/// Enriches a single app with repository information from all enabled repositories
|
||||
/// This is useful when displaying app details to show which repositories host the app
|
||||
/// Only checks database - does not trigger network fetches for performance
|
||||
Future<FDroidApp> enrichAppWithRepositories(
|
||||
FDroidApp app,
|
||||
RepositoriesProvider? repositoriesProvider,
|
||||
@@ -258,6 +259,7 @@ class AppProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
// Query all repositories in parallel for better performance
|
||||
// Use lightweight database-only check - no network fetches
|
||||
final repoChecks = await Future.wait(
|
||||
enabledRepos.map((repo) async {
|
||||
try {
|
||||
@@ -266,14 +268,14 @@ class AppProvider extends ChangeNotifier {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try to find the app in this repository via database
|
||||
final results = await _apiService.searchAppsFromRepositoryUrl(
|
||||
app.packageName, // Use exact package name for lookup
|
||||
// Check if app exists in this repository's database (lightweight, no network)
|
||||
final exists = await _apiService.hasAppInRepository(
|
||||
app.packageName,
|
||||
repo.url,
|
||||
);
|
||||
|
||||
// If found in this repository, return the source
|
||||
if (results.any((a) => a.packageName == app.packageName)) {
|
||||
if (exists) {
|
||||
return RepositorySource(name: repo.name, url: repo.url);
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -568,6 +568,44 @@ class DatabaseService {
|
||||
return apps;
|
||||
}
|
||||
|
||||
/// Checks if an app exists in a specific repository (database only, no network fetch)
|
||||
/// Returns true if the app is found in the repository's database
|
||||
Future<bool> hasAppInRepository(
|
||||
String packageName,
|
||||
String repositoryUrl,
|
||||
) async {
|
||||
try {
|
||||
final db = await database;
|
||||
|
||||
// Get repository ID by URL
|
||||
final repoResults = await db.query(
|
||||
_repositoriesTable,
|
||||
columns: ['id'],
|
||||
where: 'url = ?',
|
||||
whereArgs: [repositoryUrl],
|
||||
);
|
||||
|
||||
if (repoResults.isEmpty) {
|
||||
return false; // Repository not found in database
|
||||
}
|
||||
|
||||
final repositoryId = repoResults.first['id'] as int;
|
||||
|
||||
// Check if app exists in this repository
|
||||
final appResults = await db.query(
|
||||
_appsTable,
|
||||
columns: ['package_name'],
|
||||
where: 'package_name = ? AND repository_id = ?',
|
||||
whereArgs: [packageName, repositoryId],
|
||||
limit: 1,
|
||||
);
|
||||
|
||||
return appResults.isNotEmpty;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Searches apps by repository URL
|
||||
Future<List<FDroidApp>> searchAppsByRepository(
|
||||
String query,
|
||||
|
||||
@@ -517,6 +517,17 @@ class FDroidApiService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if an app exists in a specific repository (database only, no network fetch)
|
||||
Future<bool> hasAppInRepository(
|
||||
String packageName,
|
||||
String repositoryUrl,
|
||||
) async {
|
||||
return await _databaseService.hasAppInRepository(
|
||||
packageName,
|
||||
repositoryUrl,
|
||||
);
|
||||
}
|
||||
|
||||
/// Fetches all available categories
|
||||
Future<List<String>> fetchCategories() async {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user