Skip to content

Commit

Permalink
Significantly improved image gallery load speed using in-memory cache
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Dec 16, 2023
1 parent db69c59 commit 6a345bf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/main/assets/changelog-alpha.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/Alpha 344 (2023-12-16)
Significantly improved image gallery load speed

/Alpha 343 (2023-12-15)
Fixing regression in i.redd.it GIF links

Expand Down
1 change: 1 addition & 0 deletions src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
109/1.23
Significantly improved image gallery load speed
Update to Material 3 design elements
Visual refresh of user profile dialog
Show notification permission prompt on Android 13 and above
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/quantumbadger/redreader/image/AlbumInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.quantumbadger.redreader.image

import android.util.Log
import org.apache.commons.text.StringEscapeUtils
import org.quantumbadger.redreader.jsonwrap.JsonObject
import org.quantumbadger.redreader.reddit.kthings.ImageMetadata
Expand Down Expand Up @@ -131,17 +130,11 @@ class AlbumInfo(

fun parseRedditGallery(post: RedditPost): AlbumInfo? {

Log.i("RRDEBUG", "Got post")

val galleryItems = post.gallery_data?.items ?: return null

Log.i("RRDEBUG", "Gallery items not null")

val images = galleryItems.mapNotNull { (it as? MaybeParseError.Ok)?.value }
.mapNotNull { item ->

Log.i("RRDEBUG", "Got an image")

val mediaMetadataEntry = (post.media_metadata?.get(item.media_id) as? MaybeParseError.Ok)?.value ?:
return@mapNotNull null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RedditGalleryAPI {
companion object {
private val cache = object : LinkedHashMap<String, AlbumInfo>() {
override fun removeEldestEntry(eldest: MutableMap.MutableEntry<String, AlbumInfo>?): Boolean {
return this.size > 1000
return this.size > 100
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package org.quantumbadger.redreader.reddit.kthings

import android.os.Parcelable
import android.util.Log
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
import org.quantumbadger.redreader.image.RedditGalleryAPI
import org.quantumbadger.redreader.reddit.things.RedditThingWithIdAndType

@Suppress("PropertyName")
Expand Down Expand Up @@ -78,6 +80,14 @@ data class RedditPost(

) : RedditThingWithIdAndType, Parcelable {

init {
try {
RedditGalleryAPI.addToCache(this)
} catch (t: Throwable) {
Log.e("RedditPost", "Got error when adding post to cache", t)
}
}

@Serializable
data class GalleryData(
val items: List<MaybeParseError<GalleryItem>>
Expand Down

0 comments on commit 6a345bf

Please sign in to comment.