-
Notifications
You must be signed in to change notification settings - Fork 149
Add new Room setup to track incremental survey syncs #3929
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
Merged
andreia-ferreira
merged 6 commits into
master
from
andreia/3867/avoid-sync-all-lois-room
Sep 9, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
467b2ec
add new room table to track sync state
andreia-ferreira c583d65
add the local store for sync survey state
andreia-ferreira 7adb96b
add query to count LOIs with unsynced non-delete changes
andreia-ferreira 6ebadac
address code review comments
andreia-ferreira c1fb9fb
Merge branch 'master' into andreia/3867/avoid-sync-all-lois-room
andreia-ferreira 8a785ba
add kdoc to LocalSurveySyncStateStore
andreia-ferreira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,176 changes: 1,176 additions & 0 deletions
1,176
app/schemas/org.groundplatform.android.data.local.room.LocalDatabase/129.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/org/groundplatform/android/data/local/room/dao/SurveySyncStateDao.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.data.local.room.dao | ||
|
|
||
| import androidx.room.Dao | ||
| import androidx.room.Query | ||
| import org.groundplatform.android.data.local.room.entity.SurveySyncStateEntity | ||
|
|
||
| @Dao | ||
| interface SurveySyncStateDao : BaseDao<SurveySyncStateEntity> { | ||
| @Query("SELECT * FROM survey_sync_state WHERE survey_id = :surveyId") | ||
| suspend fun get(surveyId: String): SurveySyncStateEntity? | ||
|
|
||
| @Query( | ||
| "UPDATE survey_sync_state SET latest_loi_server_timestamp = :latestLoiServerTimestamp WHERE survey_id = :surveyId" | ||
| ) | ||
| suspend fun updateLatestLoiServerTimestamp(surveyId: String, latestLoiServerTimestamp: Long) | ||
| } |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/org/groundplatform/android/data/local/room/entity/SurveySyncStateEntity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.data.local.room.entity | ||
|
|
||
| import androidx.room.ColumnInfo | ||
| import androidx.room.Entity | ||
| import androidx.room.ForeignKey | ||
| import androidx.room.PrimaryKey | ||
|
|
||
| @Entity( | ||
| tableName = "survey_sync_state", | ||
| foreignKeys = | ||
| [ | ||
| ForeignKey( | ||
| entity = SurveyEntity::class, | ||
| parentColumns = ["id"], | ||
| childColumns = ["survey_id"], | ||
| onDelete = ForeignKey.CASCADE, | ||
| ) | ||
| ], | ||
| ) | ||
| data class SurveySyncStateEntity( | ||
| @ColumnInfo(name = "survey_id") @PrimaryKey val surveyId: String, | ||
| @ColumnInfo(name = "latest_loi_server_timestamp") val latestLoiServerTimestamp: Long, | ||
| @ColumnInfo(name = "last_full_sync_client_timestamp") val lastFullSyncClientTimestamp: Long, | ||
| @ColumnInfo(name = "synced_data_visibility") val syncedDataVisibility: Int?, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...c/main/java/org/groundplatform/android/data/local/room/stores/RoomSurveySyncStateStore.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.data.local.room.stores | ||
|
|
||
| import javax.inject.Inject | ||
| import kotlin.time.Clock | ||
| import org.groundplatform.android.data.local.room.converter.toModelObject | ||
| import org.groundplatform.android.data.local.room.dao.SurveySyncStateDao | ||
| import org.groundplatform.android.data.local.room.dao.insertOrUpdate | ||
| import org.groundplatform.android.data.local.room.entity.SurveySyncStateEntity | ||
| import org.groundplatform.android.data.local.stores.LocalSurveySyncStateStore | ||
| import org.groundplatform.android.data.remote.firebase.protobuf.toProto | ||
| import org.groundplatform.domain.model.Survey | ||
| import org.groundplatform.domain.model.SurveySyncState | ||
|
|
||
| class RoomSurveySyncStateStore | ||
| @Inject | ||
| constructor(private val surveySyncStateDao: SurveySyncStateDao) : LocalSurveySyncStateStore { | ||
| override suspend fun get(surveyId: String): SurveySyncState? { | ||
| val entity = surveySyncStateDao.get(surveyId) | ||
| return entity?.toModelObject() | ||
| } | ||
|
|
||
| override suspend fun recordIncrementalSync( | ||
| surveyId: String, | ||
| latestLoiServerTimestamp: Long, | ||
| ) { | ||
| surveySyncStateDao.updateLatestLoiServerTimestamp(surveyId, latestLoiServerTimestamp) | ||
| } | ||
|
|
||
| override suspend fun recordFullSync( | ||
| surveyId: String, | ||
| latestLoiServerTimestamp: Long, | ||
| dataVisibility: Survey.DataVisibility?, | ||
| ) { | ||
| surveySyncStateDao.insertOrUpdate( | ||
| SurveySyncStateEntity( | ||
| surveyId = surveyId, | ||
| latestLoiServerTimestamp = latestLoiServerTimestamp, | ||
| lastFullSyncClientTimestamp = Clock.System.now().toEpochMilliseconds(), | ||
| syncedDataVisibility = dataVisibility?.toProto()?.ordinal, | ||
| ) | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/org/groundplatform/android/data/local/stores/LocalSurveySyncStateStore.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.data.local.stores | ||
|
|
||
| import org.groundplatform.domain.model.Survey | ||
| import org.groundplatform.domain.model.SurveySyncState | ||
|
|
||
| /** | ||
| * Provides access to [SurveySyncState] data in local storage. | ||
| * | ||
| * This keeps track of the latest LOI server timestamp that has been synced for a survey so a later | ||
| * sync can fetch only data that changed after that point. | ||
| */ | ||
| interface LocalSurveySyncStateStore { | ||
|
andreia-ferreira marked this conversation as resolved.
|
||
| /** Returns the sync state of the given survey, or null if it has never been fully synced. */ | ||
| suspend fun get(surveyId: String): SurveySyncState? | ||
|
|
||
| /** | ||
| * Records the latest LOI server timestamp for an incremental sync without changing the rest of | ||
| * the survey's sync state. Does nothing if the survey has never been fully synced. | ||
| */ | ||
| suspend fun recordIncrementalSync( | ||
| surveyId: String, | ||
| latestLoiServerTimestamp: Long, | ||
| ) | ||
|
|
||
| /** | ||
| * Records that the survey's LOIs were fully reconciled and replaces any existing state for it. | ||
| * [latestLoiServerTimestamp] becomes the latest server timestamp used for later incremental | ||
| * syncs, and [dataVisibility] stores the visibility used to fetch the data so later changes can | ||
| * be detected. | ||
| */ | ||
| suspend fun recordFullSync( | ||
| surveyId: String, | ||
| latestLoiServerTimestamp: Long, | ||
| dataVisibility: Survey.DataVisibility?, | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.