@ -15,30 +15,40 @@ public class KeyExporter @Inject constructor(
val allKeys : Long ,
val validKeys : Long ,
val encryptedGroups : Long ,
val validGroups : Long
val validGroups : Long ,
val emptyGroups : Long
) {
val validKeysFraction : Double = if ( allKeys == 0L ) {
1.0
} else {
validKeys . toDouble ( ) / allKeys
}
val validGroupsFraction : Double = if ( encryptedGroups == 0L ) {
1.0
} else {
validGroups . toDouble ( ) / encryptedGroups
}
val emptyGroupsFraction : Double = if ( encryptedGroups == 0L ) {
1.0
} else {
emptyGroups . toDouble ( ) / encryptedGroups
}
}
public suspend fun count ( ) : Stats {
return database . execute { connection ->
val encryptedGroups : Long
val validGroups : Long
val emptyGroups : Long
connection . prepareStatement (
"""
SELECT
COUNT ( * ) ,
COUNT ( * ) FILTER ( WHERE c . key _id IS NOT NULL )
COUNT ( * ) FILTER ( WHERE c . key _id IS NOT NULL ) ,
COUNT ( * ) FILTER ( WHERE c . key _id IS NULL AND c . empty _loc )
FROM containers c
WHERE c . encrypted
""" .trimIndent()
@ -48,6 +58,7 @@ public class KeyExporter @Inject constructor(
encryptedGroups = rows . getLong ( 1 )
validGroups = rows . getLong ( 2 )
emptyGroups = rows . getLong ( 3 )
}
}
@ -65,7 +76,7 @@ public class KeyExporter @Inject constructor(
val allKeys = rows . getLong ( 1 )
val validKeys = rows . getLong ( 2 )
Stats ( allKeys , validKeys , encryptedGroups , validGroups )
Stats ( allKeys , validKeys , encryptedGroups , validGroups , emptyGroups )
}
}
}