Skip to content

Commit 3e69b4a

Browse files
authored
Fix suggestions to add descriptions when description is empty. (#6487)
* Fix suggestions to add descriptions when description is empty. * Break out into function.
1 parent f357109 commit 3e69b4a

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

app/src/main/java/org/wikipedia/suggestededits/provider/EditingSuggestionsProvider.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ object EditingSuggestionsProvider {
6666
var tries = 0
6767
while (tries++ <= retryLimit && title.isEmpty()) {
6868
// Fetch a batch of random articles, and get the ones that have no description.
69-
val resultsWithNoDescription = ServiceFactory.get(wiki).getRandomPages().query?.pages?.filter {
70-
it.description.isNullOrEmpty()
71-
}.orEmpty()
69+
val resultsWithNoDescription = fetchArticlesWithNullDescription(wiki)
7270

7371
articlesWithMissingDescriptionCacheLang = wiki.languageCode
7472

@@ -120,9 +118,7 @@ object EditingSuggestionsProvider {
120118
var tries = 0
121119
while (tries++ <= retryLimit && titles == null) {
122120
// Fetch a batch of random articles from the target language wiki, and get ones that have no description.
123-
val resultsWithNoDescription = ServiceFactory.get(targetWiki).getRandomPages().query?.pages?.filter {
124-
it.description.isNullOrEmpty()
125-
}.orEmpty()
121+
val resultsWithNoDescription = fetchArticlesWithNullDescription(targetWiki)
126122

127123
articlesWithTranslatableDescriptionCacheFromLang = sourceWiki.languageCode
128124
articlesWithTranslatableDescriptionCacheToLang = targetLang
@@ -172,6 +168,15 @@ object EditingSuggestionsProvider {
172168
return pair
173169
}
174170

171+
private suspend fun fetchArticlesWithNullDescription(targetWiki: WikiSite): List<MwQueryPage> {
172+
return ServiceFactory.get(targetWiki).getRandomPages().query?.pages?.filter {
173+
// Important: we only want pages where the description is specifically null,
174+
// instead of an empty string. An empty string implies the description is set
175+
// to "none", which means the editors don't want a description added.
176+
it.description == null
177+
}.orEmpty()
178+
}
179+
175180
suspend fun getNextImageWithMissingCaption(lang: String, retryLimit: Long = MAX_RETRY_LIMIT): String {
176181
var title = ""
177182
withContext(Dispatchers.IO) {

0 commit comments

Comments
 (0)