Skip to content

Commit

Permalink
fix: Do Not Wipe Bookmarks On Failure
Browse files Browse the repository at this point in the history
Once bookmarks were aggregated for an account, on failed sync attempts,
previously bookmarks were wiped.
Ensure bookmarks are kept if a sync attempt fails on an account with
bookmarks.
  • Loading branch information
vkhitrin committed Dec 6, 2024
1 parent 08345d5 commit 1833d76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
36 changes: 17 additions & 19 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,29 +519,27 @@ impl Application for Cosmicding {
}
Message::BookmarksView(message) => commands.push(self.bookmarks_view.update(message)),
Message::StartRefreshBookmarksForAllAccounts => {
if !self.bookmarks_view.bookmarks.is_empty() {
let message = |x: Vec<DetailedResponse>| {
cosmic::app::Message::App(Message::DoneRefreshBookmarksForAllAccounts(x))
};
if !self.accounts_view.accounts.is_empty() {
commands.push(Task::perform(
http::fetch_bookmarks_from_all_accounts(
self.accounts_view.accounts.clone(),
),
message,
));
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-bookmarks")))
.map(cosmic::app::Message::App),
);
}
let message = |x: Vec<DetailedResponse>| {
cosmic::app::Message::App(Message::DoneRefreshBookmarksForAllAccounts(x))
};
if !self.accounts_view.accounts.is_empty() {
commands.push(Task::perform(
http::fetch_bookmarks_from_all_accounts(
self.accounts_view.accounts.clone(),
),
message,
));
commands.push(
self.toasts
.push(widget::toaster::Toast::new(fl!("refreshed-bookmarks")))
.map(cosmic::app::Message::App),
);
}
}
Message::DoneRefreshBookmarksForAllAccounts(remote_responses) => {
for response in remote_responses {
block_on(async {
db::SqliteDatabase::cache_bookmarks_for_acount(
db::SqliteDatabase::aggregate_bookmarks_for_acount(
&mut self.db,
&response.account,
response.bookmarks.unwrap_or_else(Vec::new),
Expand Down Expand Up @@ -583,7 +581,7 @@ impl Application for Cosmicding {
Message::DoneRefreshBookmarksForAccount(account, remote_responses) => {
for response in remote_responses {
block_on(async {
db::SqliteDatabase::cache_bookmarks_for_acount(
db::SqliteDatabase::aggregate_bookmarks_for_acount(
&mut self.db,
&account,
response.bookmarks.unwrap_or_else(Vec::new),
Expand Down
14 changes: 7 additions & 7 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl SqliteDatabase {
// .await
// .unwrap();
//}
pub async fn cache_bookmarks_for_acount(
pub async fn aggregate_bookmarks_for_acount(
&mut self,
account: &Account,
bookmarks: Vec<Bookmark>,
Expand All @@ -145,12 +145,12 @@ impl SqliteDatabase {
let delete_query: &str = "DELETE FROM Bookmarks where user_account_id = $1;";
let update_timestamp_query =
"UPDATE UserAccounts SET last_sync_status=$2, last_sync_timestamp=$3 WHERE id=$1";
sqlx::query(delete_query)
.bind(account.id)
.execute(&mut self.conn)
.await
.unwrap();
if !bookmarks.is_empty() {
if response_successful {
sqlx::query(delete_query)
.bind(account.id)
.execute(&mut self.conn)
.await
.unwrap();
for bookmark in bookmarks {
self.add_bookmark(&bookmark).await;
}
Expand Down

0 comments on commit 1833d76

Please sign in to comment.