Skip to content
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

[mkcal] Ensure that insertion pattern from ICalFormat::fromRawString(… #7

Merged
merged 1 commit into from Oct 12, 2021

Conversation

dcaliste
Copy link
Contributor

…) is working.

If an incidence is already in the calendar with a lower revision,
the incidence is deleted from the calendar and added again in the
new revision. This commit ensures that deleting an event and adding
an event with the same UID,RecID will actually modify it in the
database.

This comes from a brainstorm started by this forum thread : https://forum.sailfishos.org/t/bug-4-2-0-21-cannot-import-calendar-entries-via-ics-file/7988/13
If the user is importing data with a same UID but with an increasing revision (not exactly the user case), and if the nemo-qml-plugin-calendar was actually loading the calendar before expanding it with the ICS data (which is not the case neither at the moment), the scheme used in icalformat_p.cpp#2809 in KCalendarCore is not working in mKCal at the moment.

Indeed, the events are deleted after being inserted in SQliteStorage::save(). So the insertion of the revised incidence is failing because of UNIQUE violation on the UID,RecID pair, and then the old incidence is deleted from the database. So at the end we have lost the incidence...

@chriadam and @pvuorela this is correcting this behaviour. At the moment, this deletion + addition scheme is not used anywhere but since it is actually used upstream in KCalendarCore, we may use it later.

@dcaliste
Copy link
Contributor Author

Thinking about it a bit more, one could also move the delete action in the ::save() routine before the insertion action. What do you think is a better idea ?

while (deleted != d->mIncidencesToDelete.end()) {
if ((*deleted)->recurrenceId() == incidence->recurrenceId()) {
deleted = d->mIncidencesToDelete.erase(deleted);
calendarIncidenceChanged(incidence);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this method updates the incidence in the database with the new values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact, it's the one that is called when an incidence is modified.

@chriadam
Copy link
Contributor

chriadam commented Sep 28, 2021

Am I understanding correctly, that there are two possible orderings (within a transaction): (delete, add) or (add, delete); this PR basically ensures that the first one (i.e. delete followed by add) works correctly, by "un-deleting" the event with that UID/recID in the second (add) step?

/edit: adding discussion from IRC: yes, the PR converts the (delete+add) into an (update) basically. Note that the other proposed solution (re-ordering the operations) might cause issues in the (add+delete) transaction case.

++deleted;
}
}
} else if (!d->mIncidencesToInsert.contains(incidence->uid(), incidence) && !d->mIsLoading) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be best to now hoist this d->mIsLoading check up, so that we early-out return prior to initializing the deleted variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's right. Updated.

@chriadam
Copy link
Contributor

chriadam commented Oct 5, 2021

Also, please add "Contributes to JB#55786" to the commit message - thanks!

…) is working. Contributes to JB#55786

If an incidence is already in the calendar with a lower revision,
the incidence is deleted from the calendar and added again in the
new revision. This commit ensures that deleting an event and adding
an event with the same UID,RecID will actually modify it in the
database.
@dcaliste
Copy link
Contributor Author

dcaliste commented Oct 5, 2021

Commit message added.

@chriadam
Copy link
Contributor

Thanks very much!

@chriadam chriadam merged commit 6cd6a08 into sailfishos:master Oct 12, 2021
@dcaliste dcaliste deleted the fromIcsData branch October 12, 2021 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants