documentation
This commit is contained in:
@@ -44,20 +44,21 @@ impl LocalMusicBrainzFetcher {
|
||||
/// Check whether the database has been populated with data.
|
||||
pub fn is_available(&self) -> bool {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
// Check if the mb_artists table exists and has rows
|
||||
// Check if the mb_artists table exists and has at least one row.
|
||||
// Use EXISTS (SELECT 1 ...) instead of COUNT(*) to avoid scanning the entire table.
|
||||
conn.query_row(
|
||||
"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='mb_artists'",
|
||||
"SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='mb_artists')",
|
||||
[],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|row| row.get::<_, bool>(0),
|
||||
)
|
||||
.map(|c| c > 0)
|
||||
.unwrap_or(false)
|
||||
&& conn
|
||||
.query_row("SELECT COUNT(*) FROM mb_artists LIMIT 1", [], |row| {
|
||||
row.get::<_, i32>(0)
|
||||
})
|
||||
.unwrap_or(0)
|
||||
> 0
|
||||
.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM mb_artists LIMIT 1)",
|
||||
[],
|
||||
|row| row.get::<_, bool>(0),
|
||||
)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Get statistics about the imported data.
|
||||
|
||||
Reference in New Issue
Block a user