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

Feature/fga/simplify timeline logic #6318

Merged
merged 10 commits into from
Jun 21, 2022

Conversation

ganfra
Copy link
Contributor

@ganfra ganfra commented Jun 15, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Simplify the management of timeline events and chunks :

  • Always delete all chunks of the room when having a gappy sync
  • Always insert timeline events in a chunk and don't try to link overlapping chunks

Motivation and context

There was multiple scenarios where we had missing messages or loops in timeline.
This fixes #6312 and fixes #5166

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

val chunkEntity = if (!isLimited && lastChunk != null) {
lastChunk
} else {
// Delete all chunks of the room in case of gap.
ChunkEntity.findAll(realm, roomId).forEach {
it.deleteOnCascade(false, canDeleteRoot = true)
Copy link
Member

Choose a reason for hiding this comment

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

canDeleteRoot = true is there a risk to delete state event here? Or Event needed for aggregation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will delete everything except state events

@ganfra ganfra requested review from a team, Claire1817, mnaturel and bmarty and removed request for a team June 17, 2022 10:03
…al/database/migration/MigrateSessionTo030.kt

Co-authored-by: Benoit Marty <benoitm@matrix.org>
chunk.getList(ChunkEntityFields.TIMELINE_EVENTS.`$`).clearWith { timelineEvent ->
// Don't delete state events
if (timelineEvent.isNull(TimelineEventEntityFields.ROOT.STATE_KEY)) {
timelineEvent.getObject(TimelineEventEntityFields.ROOT.`$`)?.deleteFromRealm()
Copy link
Contributor

Choose a reason for hiding this comment

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

I see there may be also other entities attached to the event such as: EventAnnotationsSummaryEntity and ReadReceiptsSummaryEntity. Is it okay to keep them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes we can keep them, they are kind of independent

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -445,7 +445,7 @@ internal class TimelineChunk(
Timber.e(failure, "Failed to fetch from server")
LoadMoreResult.FAILURE
}
return if (loadMoreResult == LoadMoreResult.SUCCESS) {
return if (loadMoreResult != LoadMoreResult.FAILURE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, is it intended to call loadMore when result is LoadMoreResult.REACHED_END?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the downside of linking the last permalink chunk to the lastForward chunk... I still don't know if we want this or just add timeline events from sync on both chunks instead

Copy link
Contributor

@mnaturel mnaturel left a comment

Choose a reason for hiding this comment

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

Good for me. I have just added one question about something I was not sure.

@sonarcloud
Copy link

sonarcloud bot commented Jun 21, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

33.3% 33.3% Coverage
0.0% 0.0% Duplication

@ouchadam ouchadam merged commit b07e0a4 into develop Jun 21, 2022
@ouchadam ouchadam deleted the feature/fga/simplify_timeline_logic branch June 21, 2022 13:42
ouchadam added a commit that referenced this pull request Jun 21, 2022
* Sync: delete all previous chunks in case of gappy sync

* Chunk: dont link chunks if we find existing timeline event (keep multiple timeline events in db)

* Timeline : remove some unused code

* Clean and add changelog

* Timeline: set named argument

* Timeline: avoid restarting the timeline when there is a CancellationException due to permalink

* Timeline: add migration to clean up old (broken) chunks

* Update matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt

Co-authored-by: Benoit Marty <benoitm@matrix.org>

* Timeline: try to fix test

* ignoring broken instrumentation test in order to release

Co-authored-by: ganfra <francoisg@element.io>
Co-authored-by: Benoit Marty <benoitm@matrix.org>
Co-authored-by: Adam Brown <adampsbrown@gmail.com>
@@ -0,0 +1 @@
Fix loop in timeline and simplify management of chunks and timeline events.

Choose a reason for hiding this comment

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

Does this also close the following? They seem like duplicates of #5166 anway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants