Skip to content
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

Database bug fix #5902

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ abstract class NotForUploadStatusDao {
* Insert into Not For Upload status.
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insert(notForUploadStatus: NotForUploadStatus)
abstract suspend fun insert(notForUploadStatus: NotForUploadStatus)

/**
* Delete Not For Upload status entry.
*/
@Delete
abstract fun delete(notForUploadStatus: NotForUploadStatus)
abstract suspend fun delete(notForUploadStatus: NotForUploadStatus)

/**
* Query Not For Upload status with image sha1.
*/
@Query("SELECT * FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ")
abstract fun getFromImageSHA1(imageSHA1: String): NotForUploadStatus?
abstract suspend fun getFromImageSHA1(imageSHA1: String): NotForUploadStatus?

/**
* Asynchronous image sha1 query.
Expand All @@ -38,7 +38,7 @@ abstract class NotForUploadStatusDao {
* Deletion Not For Upload status with image sha1.
*/
@Query("DELETE FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ")
abstract fun deleteWithImageSHA1(imageSHA1: String)
abstract suspend fun deleteWithImageSHA1(imageSHA1: String)

/**
* Asynchronous image sha1 deletion.
Expand All @@ -49,5 +49,5 @@ abstract class NotForUploadStatusDao {
* Check whether the imageSHA1 is present in database
*/
@Query("SELECT COUNT() FROM images_not_for_upload_table WHERE imageSHA1 = (:imageSHA1) ")
abstract fun find(imageSHA1: String): Int
abstract suspend fun find(imageSHA1: String): Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ abstract class UploadedStatusDao {
* Insert into uploaded status.
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insert(uploadedStatus: UploadedStatus)
abstract suspend fun insert(uploadedStatus: UploadedStatus)

/**
* Update uploaded status entry.
*/
@Update
abstract fun update(uploadedStatus: UploadedStatus)
abstract suspend fun update(uploadedStatus: UploadedStatus)

/**
* Delete uploaded status entry.
*/
@Delete
abstract fun delete(uploadedStatus: UploadedStatus)
abstract suspend fun delete(uploadedStatus: UploadedStatus)

/**
* Query uploaded status with image sha1.
*/
@Query("SELECT * FROM uploaded_table WHERE imageSHA1 = (:imageSHA1) ")
abstract fun getFromImageSHA1(imageSHA1: String): UploadedStatus?
abstract suspend fun getFromImageSHA1(imageSHA1: String): UploadedStatus?

/**
* Query uploaded status with modified image sha1.
*/
@Query("SELECT * FROM uploaded_table WHERE modifiedImageSHA1 = (:modifiedImageSHA1) ")
abstract fun getFromModifiedImageSHA1(modifiedImageSHA1: String): UploadedStatus?
abstract suspend fun getFromModifiedImageSHA1(modifiedImageSHA1: String): UploadedStatus?

/**
* Asynchronous insert into uploaded status table.
Expand All @@ -55,7 +55,7 @@ abstract class UploadedStatusDao {
* Check whether the imageSHA1 is present in database
*/
@Query("SELECT COUNT() FROM uploaded_table WHERE imageSHA1 = (:imageSHA1) AND imageResult = (:imageResult) ")
abstract fun findByImageSHA1(
abstract suspend fun findByImageSHA1(
imageSHA1: String,
imageResult: Boolean,
): Int
Expand All @@ -66,7 +66,7 @@ abstract class UploadedStatusDao {
@Query(
"SELECT COUNT() FROM uploaded_table WHERE modifiedImageSHA1 = (:modifiedImageSHA1) AND modifiedImageResult = (:modifiedImageResult) ",
)
abstract fun findByModifiedImageSHA1(
abstract suspend fun findByModifiedImageSHA1(
modifiedImageSHA1: String,
modifiedImageResult: Boolean,
): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import fr.free.nrw.commons.utils.CustomSelectorUtils
import fr.free.nrw.commons.utils.CustomSelectorUtils.Companion.checkWhetherFileExistsOnCommonsUsingSHA1
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Calendar
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -65,7 +65,7 @@ class ImageLoader
/**
* Coroutine Scope.
*/
private val scope: CoroutineScope = MainScope()
private val scope: CoroutineScope = CoroutineScope(Dispatchers.IO)

/**
* Query image and setUp the view.
Expand Down
12 changes: 3 additions & 9 deletions app/src/main/java/fr/free/nrw/commons/nearby/PlaceDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,21 @@ public abstract class PlaceDao {
*/
public Completable save(final Place place) {
return Completable
.fromAction(() -> {
saveSynchronous(place);
});
.fromAction(() -> saveSynchronous(place));
}

/**
* Deletes all Place objects from the database.
*
* @return A Completable that completes once the deletion operation is done.
*/
@Query("DELETE FROM place")
public abstract void deleteAllSynchronous();

/**
* Deletes all Place objects from the database.
*
* @return A Completable that completes once the deletion operation is done.
*/
public Completable deleteAll() {
return Completable
.fromAction(() -> {
deleteAllSynchronous();
});
return Completable.fromAction(this::deleteAllSynchronous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ abstract class DepictsDao {
private val maxItemsAllowed = 10

@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insert(depictedItem: Depicts)
abstract suspend fun insert(depictedItem: Depicts)

@Query("Select * From depicts_table order by lastUsed DESC")
abstract fun getAllDepicts(): List<Depicts>
abstract suspend fun getAllDepicts(): List<Depicts>

@Query("Select * From depicts_table order by lastUsed DESC LIMIT :n OFFSET 10")
abstract fun getDepictsForDeletion(n: Int): List<Depicts>
abstract suspend fun getDepictsForDeletion(n: Int): List<Depicts>

@Delete
abstract fun delete(depicts: Depicts)
abstract suspend fun delete(depicts: Depicts)

/**
* Gets all Depicts objects from the database, ordered by lastUsed in descending order.
*
* @return A list of Depicts objects.
* @return Deferred list of Depicts objects.
*/
fun depictsList(): Deferred<List<Depicts>> =
CoroutineScope(Dispatchers.IO).async {
Expand All @@ -48,7 +48,7 @@ abstract class DepictsDao {
*
* @param depictedItem The Depicts object to insert.
*/
private fun insertDepict(depictedItem: Depicts) =
fun insertDepict(depictedItem: Depicts) =
CoroutineScope(Dispatchers.IO).launch {
insert(depictedItem)
}
Expand All @@ -59,7 +59,7 @@ abstract class DepictsDao {
* @param n The number of depicts to delete.
* @return A list of Depicts objects to delete.
*/
private suspend fun depictsForDeletion(n: Int): Deferred<List<Depicts>> =
fun depictsForDeletion(n: Int): Deferred<List<Depicts>> =
CoroutineScope(Dispatchers.IO).async {
getDepictsForDeletion(n)
}
Expand All @@ -69,7 +69,7 @@ abstract class DepictsDao {
*
* @param depicts The Depicts object to delete.
*/
private suspend fun deleteDepicts(depicts: Depicts) =
fun deleteDepicts(depicts: Depicts) =
CoroutineScope(Dispatchers.IO).launch {
delete(depicts)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import fr.free.nrw.commons.upload.UploadProgressActivity
import fr.free.nrw.commons.upload.UploadResult
import fr.free.nrw.commons.wikidata.WikidataEditService
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
Expand Down Expand Up @@ -534,7 +534,7 @@ class UploadWorker(
contribution.contentUri?.let {
val imageSha1 = contribution.imageSHA1.toString()
val modifiedSha1 = fileUtilsWrapper.getSHA1(fileUtilsWrapper.getFileInputStream(contribution.localUri?.path))
MainScope().launch {
CoroutineScope(Dispatchers.IO).launch {
uploadedStatusDao.insertUploaded(
UploadedStatus(
imageSha1,
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android.enableR8.fullMode=false
KOTLIN_VERSION=1.9.22
LEAK_CANARY_VERSION=2.10
DAGGER_VERSION=2.23
ROOM_VERSION=2.5.0
ROOM_VERSION=2.6.1
PREFERENCE_VERSION=1.1.0
CORE_KTX_VERSION=1.9.0
ADAPTER_DELEGATES_VERSION=4.3.0
Expand Down
Loading