Skip to content

Commit

Permalink
Fix database sync error
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Jul 11, 2024
1 parent 1459a4e commit 870d8ef
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class SyncedDatabaseHelper(
suspend fun insertFeedItems(feedItems: List<SyncedFeedItem>) =
getDbRef().transactionWithContext(backgroundDispatcher) {
feedItems.forEach { feedItem ->
getDbRef().syncedFeedItemQueries.insertOrReplaceSyncedFeedItem(
getDbRef().syncedFeedItemQueries.insertOrIgnoreSyncedFeedItem(
url_hash = feedItem.id,
is_read = feedItem.isRead,
is_bookmarked = feedItem.isBookmarked,
Expand All @@ -171,6 +171,11 @@ class SyncedDatabaseHelper(

suspend fun setFeedItemAsRead(feedItemId: FeedItemId, isRead: Boolean) =
getDbRef().transactionWithContext(backgroundDispatcher) {
getDbRef().syncedFeedItemQueries.insertOrIgnoreSyncedFeedItem(
url_hash = feedItemId.id,
is_read = isRead,
is_bookmarked = false,
)
getDbRef().syncedFeedItemQueries.updateIsRead(
isRead = isRead,
urlHash = feedItemId.id,
Expand All @@ -180,6 +185,11 @@ class SyncedDatabaseHelper(

suspend fun setFeedItemAsBookmarked(feedItemId: FeedItemId, isBookmarked: Boolean) =
getDbRef().transactionWithContext(backgroundDispatcher) {
getDbRef().syncedFeedItemQueries.insertOrIgnoreSyncedFeedItem(
url_hash = feedItemId.id,
is_read = false,
is_bookmarked = isBookmarked,
)
getDbRef().syncedFeedItemQueries.updateIsBookmarked(
isBookmarked = isBookmarked,
urlHash = feedItemId.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ CREATE TABLE synced_feed_item(
is_bookmarked INTEGER AS Boolean NOT NULL DEFAULT 0
);

insertOrReplaceSyncedFeedItem:
INSERT OR REPLACE INTO synced_feed_item(url_hash, is_read, is_bookmarked)
insertOrIgnoreSyncedFeedItem:
INSERT OR IGNORE INTO synced_feed_item(url_hash, is_read, is_bookmarked)
VALUES (?, ?,?);

deleteSyncedFeedItem:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WITH table_counts AS (
)
SELECT
CASE
WHEN item_count = 0 AND source_count = 0 AND category_count = 0 THEN 0
WHEN item_count = 0 OR source_count = 0 OR category_count = 0 THEN 0
ELSE 1
END AS is_database_empty
FROM table_counts;
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class DropboxDataSourceIos: DropboxDataSource {

} else if let error = error {
print(error)
KotlinDependencies.shared.getLogger(tag: "DropboxDataSourceIos").e(messageString: error.localizedDescription)
completionHandler(nil, DropboxErrors.downloadError(reason: error.description))
}
}
Expand Down Expand Up @@ -101,6 +102,7 @@ class DropboxDataSourceIos: DropboxDataSource {
completionHandler(uploadResult, nil)
} else if let error = error {
print(error)
KotlinDependencies.shared.getLogger(tag: "DropboxDataSourceIos").e(messageString: error.localizedDescription)
completionHandler(nil, DropboxErrors.uploadError(reason: error.description))
}
}
Expand Down
12 changes: 11 additions & 1 deletion iosApp/Source/Accounts/Dropbox/DropboxSyncScreenContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct DropboxSyncScreenContent: View {
VStack {
Form {
Section {
VStack {
VStack(alignment: .leading) {
Text(feedFlowStrings.dropboxSyncCommonDescription)
.font(.body)

Expand All @@ -165,6 +165,16 @@ struct DropboxSyncScreenContent: View {
}
}

#Preview("Unlinked") {
DropboxSyncScreenContent(
connectionState: DropboxConnectionUiState.Unlinked(),
onDropboxAuthSuccess: {},
onBackupClick: {},
onDisconnectClick: {}
)
}


#Preview("Loading") {
DropboxSyncScreenContent(
connectionState: DropboxConnectionUiState.Linked(syncState: DropboxSyncUIState.Loading()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct ImportExportContent: View {
.padding(.horizontal, Spacing.medium)

Spacer()
}
}.frame(maxWidth: .infinity)
}

@ViewBuilder
Expand All @@ -138,6 +138,7 @@ struct ImportExportContent: View {
.multilineTextAlignment(.center)
Spacer()
}
.frame(maxWidth: .infinity)
}

@ViewBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ internal class FeedSyncer(
private val appDatabaseHelper: DatabaseHelper,
private val logger: Logger,
) {
suspend fun performSync() {
syncFeedSourceCategory()
syncFeedSource()
syncFeedItem()
}

suspend fun populateSyncDbIfEmpty() {
if (syncedDatabaseHelper.isDatabaseEmpty()) {
Expand Down

0 comments on commit 870d8ef

Please sign in to comment.