Add launch statistics to dashboard
This commit is contained in:
@@ -1744,6 +1744,53 @@ impl Database {
|
||||
Ok(self.conn.last_insert_rowid())
|
||||
}
|
||||
|
||||
// --- Launch statistics ---
|
||||
|
||||
pub fn get_top_launched(&self, limit: i32) -> SqlResult<Vec<(String, u64)>> {
|
||||
let mut stmt = self.conn.prepare(
|
||||
"SELECT a.app_name, COUNT(l.id) as cnt
|
||||
FROM launch_events l
|
||||
JOIN appimages a ON a.id = l.appimage_id
|
||||
GROUP BY l.appimage_id
|
||||
ORDER BY cnt DESC
|
||||
LIMIT ?1"
|
||||
)?;
|
||||
let rows = stmt.query_map(params![limit], |row| {
|
||||
Ok((
|
||||
row.get::<_, Option<String>>(0)?.unwrap_or_else(|| "Unknown".to_string()),
|
||||
row.get::<_, u64>(1)?,
|
||||
))
|
||||
})?;
|
||||
rows.collect()
|
||||
}
|
||||
|
||||
pub fn get_total_launch_count(&self) -> SqlResult<u64> {
|
||||
self.conn.query_row(
|
||||
"SELECT COUNT(*) FROM launch_events",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_last_launch(&self) -> SqlResult<Option<(String, String)>> {
|
||||
match self.conn.query_row(
|
||||
"SELECT a.app_name, l.launched_at
|
||||
FROM launch_events l
|
||||
JOIN appimages a ON a.id = l.appimage_id
|
||||
ORDER BY l.launched_at DESC
|
||||
LIMIT 1",
|
||||
[],
|
||||
|row| Ok((
|
||||
row.get::<_, Option<String>>(0)?.unwrap_or_else(|| "Unknown".to_string()),
|
||||
row.get::<_, String>(1)?,
|
||||
)),
|
||||
) {
|
||||
Ok(pair) => Ok(Some(pair)),
|
||||
Err(rusqlite::Error::QueryReturnedNoRows) => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
// --- Source URL ---
|
||||
|
||||
pub fn set_source_url(&self, id: i64, url: Option<&str>) -> SqlResult<()> {
|
||||
|
||||
Reference in New Issue
Block a user