From e8c59d76482819f73210ff5a045b61a35a7ace41 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 14 May 2023 21:56:41 -0700 Subject: [PATCH] Optimizations --- app/src/main/java/gallery/memories/NativeX.kt | 8 +++++++- app/src/main/java/gallery/memories/service/DbService.kt | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/gallery/memories/NativeX.kt b/app/src/main/java/gallery/memories/NativeX.kt index b8f8ad7a..d3e9fdd3 100644 --- a/app/src/main/java/gallery/memories/NativeX.kt +++ b/app/src/main/java/gallery/memories/NativeX.kt @@ -72,10 +72,16 @@ import java.net.URLDecoder } // Allow CORS from all origins - response.responseHeaders = mapOf( + response.responseHeaders = mutableMapOf( "Access-Control-Allow-Origin" to "*", "Access-Control-Allow-Headers" to "*" ) + + // Cache image responses for 7 days + if (path.matches(API.IMAGE_PREVIEW) || path.matches(API.IMAGE_FULL)) { + response.responseHeaders["Cache-Control"] = "max-age=604800" + } + return response } diff --git a/app/src/main/java/gallery/memories/service/DbService.kt b/app/src/main/java/gallery/memories/service/DbService.kt index cc8b8075..8cd0df7a 100644 --- a/app/src/main/java/gallery/memories/service/DbService.kt +++ b/app/src/main/java/gallery/memories/service/DbService.kt @@ -4,7 +4,7 @@ import android.content.Context import android.database.sqlite.SQLiteOpenHelper import android.database.sqlite.SQLiteDatabase -class DbService(context: Context) : SQLiteOpenHelper(context, "memories", null, 26) { +class DbService(context: Context) : SQLiteOpenHelper(context, "memories", null, 27) { override fun onCreate(db: SQLiteDatabase) { db.execSQL(""" CREATE TABLE images ( @@ -18,6 +18,11 @@ class DbService(context: Context) : SQLiteOpenHelper(context, "memories", null, flag INTEGER ) """) + + // Add index on local_id, dayid, and flag + db.execSQL("CREATE INDEX images_local_id ON images (local_id)") + db.execSQL("CREATE INDEX images_dayid ON images (dayid)") + db.execSQL("CREATE INDEX images_flag ON images (flag)") } override fun onUpgrade(database: SQLiteDatabase, oldVersion: Int, newVersion: Int) {