Skip to content

limit installed apps icons to 500 instead of 100 #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 48 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ impl App {
apps: &Apps,
backends: &Backends,
filter_map: F,
max_results: usize,
) -> Vec<SearchResult> {
let mut results: Vec<SearchResult> = apps
.par_iter()
Expand Down Expand Up @@ -814,7 +815,7 @@ impl App {
});
// Load only enough icons to show one page of results
//TODO: load in background
for result in results.iter_mut().take(MAX_RESULTS) {
for result in results.iter_mut().take(max_results) {
let Some(backend) = backends.get(result.backend_name) else {
continue;
};
Expand All @@ -837,16 +838,20 @@ impl App {
async move {
tokio::task::spawn_blocking(move || {
let start = Instant::now();
let results =
Self::generic_search(&apps, &backends, |_id, info, _installed| {
let results = Self::generic_search(
&apps,
&backends,
|_id, info, _installed| {
for category in categories {
//TODO: contains doesn't work due to type mismatch
if info.categories.iter().any(|x| x == category.id()) {
return Some(-(info.monthly_downloads as i64));
}
}
None
});
},
MAX_RESULTS,
);
let duration = start.elapsed();
log::info!(
"searched for categories {:?} in {:?}, found {} results",
Expand Down Expand Up @@ -878,10 +883,10 @@ impl App {
.iter()
.position(|choice_id| choice_id == &id.normalized())
.map(|x| x as i64)
}),
}, MAX_RESULTS),
ExplorePage::PopularApps => Self::generic_search(&apps, &backends, |_id, info, _installed| {
Some(-(info.monthly_downloads as i64))
}),
}, MAX_RESULTS),
ExplorePage::MadeForCosmic => {
let provide = AppProvide::Id("com.system76.CosmicApplication".to_string());
Self::generic_search(&apps, &backends, |_id, info, _installed| {
Expand All @@ -890,12 +895,12 @@ impl App {
} else {
None
}
})
}, MAX_RESULTS)
},
ExplorePage::NewApps => Self::generic_search(&apps, &backends, |_id, _info, _installed| {
//TODO
None
}),
}, MAX_RESULTS),
ExplorePage::RecentlyUpdated => Self::generic_search(&apps, &backends, |id, info, _installed| {
// Finds the newest release and sorts from newest to oldest
//TODO: appstream release info is often incomplete
Expand All @@ -913,7 +918,7 @@ impl App {
}
}
Some(min_weight)
}),
}, MAX_RESULTS),
_ => {
let categories = explore_page.categories();
Self::generic_search(&apps, &backends, |_id, info, _installed| {
Expand All @@ -924,7 +929,7 @@ impl App {
}
}
None
})
}, MAX_RESULTS)
}
};
let duration = start.elapsed();
Expand All @@ -950,13 +955,18 @@ impl App {
async move {
tokio::task::spawn_blocking(move || {
let start = Instant::now();
let results = Self::generic_search(&apps, &backends, |id, _info, installed| {
if installed {
Some(if id.is_system() { -1 } else { 0 })
} else {
None
}
});
let results = Self::generic_search(
&apps,
&backends,
|id, _info, installed| {
if installed {
Some(if id.is_system() { -1 } else { 0 })
} else {
None
}
},
500,
);
let duration = start.elapsed();
log::info!(
"searched for installed in {:?}, found {} results",
Expand Down Expand Up @@ -1019,8 +1029,10 @@ impl App {
async move {
tokio::task::spawn_blocking(move || {
let start = Instant::now();
let results =
Self::generic_search(&apps, &backends, |_id, info, _installed| {
let results = Self::generic_search(
&apps,
&backends,
|_id, info, _installed| {
//TODO: improve performance
let stats_weight = |weight: i64| {
//TODO: make sure no overflows
Expand Down Expand Up @@ -1076,7 +1088,9 @@ impl App {
},
},
}
});
},
MAX_RESULTS,
);
let duration = start.elapsed();
log::info!(
"searched for {:?} in {:?}, found {} results",
Expand Down Expand Up @@ -1433,15 +1447,19 @@ impl App {
async move {
tokio::task::spawn_blocking(move || {
let start = Instant::now();
let results =
Self::generic_search(&apps, &backends, |id, _info, _installed| {
let results = Self::generic_search(
&apps,
&backends,
|id, _info, _installed| {
//TODO: fuzzy search with lower weight?
if id == &component_id {
Some(0)
} else {
None
}
});
},
MAX_RESULTS,
);
let duration = start.elapsed();
log::info!(
"searched for ID {:?} in {:?}, found {} results",
Expand Down Expand Up @@ -1520,15 +1538,19 @@ impl App {
async move {
tokio::task::spawn_blocking(move || {
let start = Instant::now();
let results =
Self::generic_search(&apps, &backends, |_id, info, _installed| {
let results = Self::generic_search(
&apps,
&backends,
|_id, info, _installed| {
//TODO: monthly downloads as weight?
if info.provides.contains(&provide) {
Some(-(info.monthly_downloads as i64))
} else {
None
}
});
},
MAX_RESULTS,
);
let duration = start.elapsed();
log::info!(
"searched for mime {:?} in {:?}, found {} results",
Expand Down