Skip to content

Commit

Permalink
resolves #362
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxcapades committed Feb 11, 2025
1 parent af3de88 commit 305994c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ interface CacheDB {

fun selectDatasetForUser(userID: UserID, datasetID: DatasetID): DatasetRecord?

// TODO: this is only used to list dataset IDs, very wasteful!!!
fun selectDatasetsForUser(userID: UserID): List<DatasetRecord>
fun selectUndeletedDatasetIDsForUser(userID: UserID): List<DatasetID>

fun selectNonPrivateDatasets(): List<DatasetRecord>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal object CacheDBImpl: CacheDB {
override fun selectDatasetForUser(userID: UserID, datasetID: DatasetID) =
connection.use { it.selectDatasetForUser(userID, datasetID) }

override fun selectDatasetsForUser(userID: UserID) = connection.use { it.selectDatasetsForUser(userID) }
override fun selectUndeletedDatasetIDsForUser(userID: UserID) = connection.use { it.selectUndeletedDatasetIDsForUser(userID) }

override fun selectNonPrivateDatasets() = connection.use { it.selectNonPrivateDatasets() }

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package vdi.component.db.cache.sql.select

import org.veupathdb.vdi.lib.common.field.DatasetID
import org.veupathdb.vdi.lib.common.field.UserID
import vdi.component.db.cache.util.*
import java.sql.Connection

// language=postgresql
private const val SQL = """
SELECT
d.dataset_id
FROM
vdi.datasets AS d
WHERE
d.owner_id = ?
AND d.is_deleted = FALSE
"""

internal fun Connection.selectUndeletedDatasetIDsForUser(userID: UserID): List<DatasetID> {
return withPreparedStatement(SQL) {
setUserID(1, userID)
withResults { map { getDatasetID("dataset_id") } }
}
}
4 changes: 2 additions & 2 deletions lib/test-utils/src/main/kotlin/vdi/test/cache-db.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fun mockCacheDB(
onSelectUploadFileSummaries: (List<DatasetID>) -> Map<DatasetID, DatasetFileSummary> = ::oneParamMap,
onSelectDatasetList: (DatasetListQuery) -> List<DatasetRecord> = ::oneParamList,
onSelectDatasetForUser: (UserID, DatasetID) -> DatasetRecord? = ::twoParamNull,
onSelectDatasetsForUser: (UserID) -> List<DatasetRecord> = ::oneParamList,
onSelectDatasetsForUser: (UserID) -> List<DatasetID> = ::oneParamList,
onSelectNonPrivateDatasets: () -> List<DatasetRecord> = ::noParamList,
onSelectSharesForDataset: DSGetter<List<DatasetShare>> = ::oneParamList,
onSelectSharesForDatasets: (List<DatasetID>) -> Map<DatasetID, List<DatasetShare>> = ::oneParamMap,
Expand Down Expand Up @@ -52,7 +52,7 @@ fun mockCacheDB(
on { selectUploadFileSummaries(any()) } doAnswer { onSelectUploadFileSummaries(it.getArgument(0)) }
on { selectDatasetList(any()) } doAnswer { onSelectDatasetList(it.getArgument(0)) }
on { selectDatasetForUser(any(), any()) } doAnswer { onSelectDatasetForUser(it.getArgument(0), it.getArgument(1)) }
on { selectDatasetsForUser(any()) } doAnswer { onSelectDatasetsForUser(it.getArgument(0)) }
on { selectUndeletedDatasetIDsForUser(any()) } doAnswer { onSelectDatasetsForUser(it.getArgument(0)) }
on { selectNonPrivateDatasets() } doAnswer { onSelectNonPrivateDatasets() }
on { selectSharesForDataset(any()) } doAnswer { onSelectSharesForDataset(it.getArgument(0)) }
on { selectSharesForDatasets(any()) } doAnswer { onSelectSharesForDatasets(it.getArgument(0)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ private fun getUserQuotaInfo(userID: UserID): UserQuotaDetails =
internal fun getCurrentQuotaUsage(userID: UserID): Long {
val sizes = DatasetStore.listDatasetImportReadyZipSizes(userID)

return CacheDB().selectDatasetsForUser(userID)
return CacheDB().selectUndeletedDatasetIDsForUser(userID)
.asSequence()
.filter { !it.isDeleted }
.map { sizes[it.datasetID] ?: 0L }
.map { sizes[it] ?: 0L }
.sum()
}

0 comments on commit 305994c

Please sign in to comment.