-
Notifications
You must be signed in to change notification settings - Fork 160
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
Added Settings to deal with newer settings & add callback threads #450
Added Settings to deal with newer settings & add callback threads #450
Conversation
@nbransby this is now tracking master, which means the JVM split for firestore is tracked. This PR can now be properly reviewed |
Updated tracking again @nbransby |
fun reference(path: String): DatabaseReference | ||
fun reference(): DatabaseReference | ||
fun setPersistenceEnabled(enabled: Boolean) | ||
fun setSettings(settings: Settings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just
fun setSettings(persistenceEnabled: Boolean = false, persistenceCacheSizeBytes: Long? = null)
What the point of making everyone write the boilerplate
database.setSettings(FirebaseDatabase.Settings.createSettings(persistenceEnabled = true, persistenceCacheSizeBytes = 2048))
?
Looking at the official android sdk, the methods are defined as follows: |
This PR inspired me to write a section on compatibility with the official firebase android sdk here: https://github.com/GitLiveApp/firebase-kotlin-sdk?tab=readme-ov-file#compatibility-with-the-official-firebase-android-sdk Can we apply those points to this PR? |
Yep, will track/correct when I have the time |
Changes now track the Android API. I did leave the LocalCacheSettings as a sealed class as opposed to an interface, so it can both be constructed through a direct constructor as well as through builders as they exist on Android. |
fun setCallbackQueue(callbackQueue: dispatch_queue_t) { | ||
ios.callbackQueue = callbackQueue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets not start adding coverage for platform specific APIs, let users use .ios
@Deprecated("Use dev.gitlive.firebase.firestore instead", replaceWith = ReplaceWith("setSettings(FirebaseFirestore.Settings.create())")) | ||
fun FirebaseFirestore.setSettings( | ||
persistenceEnabled: Boolean? = null, | ||
sslEnabled: Boolean? = null, | ||
host: String? = null, | ||
cacheSizeBytes: Long? = null, | ||
) { | ||
settings = firestoreSettings { | ||
this.sslEnabled = sslEnabled ?: true | ||
this.host = host ?: FirestoreSettings.DEFAULT_HOST | ||
this.cacheSettings = if (persistenceEnabled != false) { | ||
LocalCacheSettings.Persistent(cacheSizeBytes ?: FirestoreSettings.CACHE_SIZE_UNLIMITED) | ||
} else { | ||
val cacheSize = cacheSizeBytes ?: FirestoreSettings.CACHE_SIZE_UNLIMITED | ||
val garbageCollectionSettings = if (cacheSize == FirestoreSettings.CACHE_SIZE_UNLIMITED) { | ||
GarbageCollectorSettings.Eager | ||
} else { | ||
GarbageCollectorSettings.LRUGC(cacheSize) | ||
} | ||
LocalCacheSettings.Memory(garbageCollectionSettings) | ||
} | ||
} | ||
} | ||
|
||
@PublishedApi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving this to an extension will make it a breaking change, why not leave it in the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FirebaseFirestore is expect/actuals so it cant have default implementation. Omving to the same NativeWrapper pattern used elsewhere now
firebase-firestore/src/commonTest/kotlin/dev/gitlive/firebase/firestore/firestore.kt
Show resolved
Hide resolved
firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/LocalCacheSettings.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't comment on every change needed to comply with https://github.com/GitLiveApp/firebase-kotlin-sdk?tab=readme-ov-file#compatibility-with-the-official-firebase-android-sdk but there should be enough comments there so you can apply the same changes to the remaining classes, fields and functions
val FirestoreSettings.Companion.CACHE_SIZE_UNLIMITED get() = -1L | ||
val FirestoreSettings.Companion.DEFAULT_HOST get() = "firestore.googleapis.com" | ||
|
||
expect class FirestoreSettings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename FirebaseFirestoreSettings to match android
suspend fun disableNetwork() | ||
suspend fun enableNetwork() | ||
} | ||
|
||
val FirestoreSettings.Companion.CACHE_SIZE_UNLIMITED get() = -1L |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move inside companion object for binary compat with android
suspend fun disableNetwork() | ||
suspend fun enableNetwork() | ||
} | ||
|
||
val FirestoreSettings.Companion.CACHE_SIZE_UNLIMITED get() = -1L | ||
val FirestoreSettings.Companion.DEFAULT_HOST get() = "firestore.googleapis.com" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see this property on android?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ill make it internal only
|
||
companion object {} | ||
|
||
interface Builder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this a class with the constructors available here to match android:
https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/FirebaseFirestoreSettings.Builder
@@ -0,0 +1,90 @@ | |||
package dev.gitlive.firebase.firestore | |||
|
|||
sealed class LocalCacheSettings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sealed interface to match android
internal companion object { | ||
// Firestore cache defaults to 100MB | ||
const val DEFAULT_CACHE_SIZE = 100L*1024L*1024L | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont see this in the android sdk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/LocalCacheSettings.kt
Show resolved
Hide resolved
override fun build(): Persistent = Persistent(sizeBytes) | ||
} | ||
} | ||
data class Memory(val garbaseCollectorSettings: GarbageCollectorSettings) : LocalCacheSettings() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make constructor internal or private
firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/LocalCacheSettings.kt
Outdated
Show resolved
Hide resolved
Also I used the term binary compat a lot when technically I mean source compatibility |
Updated with fixes for remarks. Also moved the |
BTW: we have the extent methods |
Let's not start copying business logic such as this from the native SDKs as its causes a maintenance headache - you can see here the logic is more complex. Lets leverage our dependency on the native SDKs and let them do the validation. The fact you can't catch it on iOS is a good thing, an assertion like this represents a programming error, not expected runtime behavior. |
Removed then |
look like the build failed: |
Whoops, dont do things quickly in the morning :') |
Js test still failing 😅 |
Source changes pointed to an actual bug. Fixed now |
Final one for now:
This one updates Firestore/Database to provide settings. This includes fixes for deprecated Persistency settings (though not on Java as that is not tracked yet) and adds support on iOS/Android to set custom callback dispatchers. Otherwise, Firebase internally still goes to the main thread even when running in a background thread.