★ wanayoo — archive 1999 https://github.com/RocketChat/Rocket.Chat.iOS/pull/2253Nouvelle recherche | Portail wanayoo
Skip to content
This repository has been archived by the owner. It is now read-only.

[IMPROVEMENT] DataController fetching partial database messages and code improvements #2253

Conversation

@rafaelks
Copy link
Contributor

@rafaelks rafaelks commented Oct 15, 2018 •

@RocketChat/ios

This pull-request resolves couple of issues:

  1. Load initial messages partially from database instead of all messages. Right now it's loading 30 messages every page;
  2. It loads paginated result from database as well instead;
@rafaelks rafaelks added this to the 3.2.0 milestone Oct 15, 2018
@rafaelks rafaelks added this to In Progress in Cycle 10: 10/05 ~ 11/05 via automation Oct 15, 2018
@@ -291,7 +301,7 @@ final class MessagesViewModel {
guard let subscription = subscription?.validated() else { return }
guard let subscriptionDetached = subscription.unmanaged else { return }

let messages = subscription.fetchMessages(50, lastMessageDate: oldestMessage)
let messages = subscription.fetchMessages(30, lastMessageDate: oldestMessage)

This comment has been minimized.

@filipealva

filipealva Oct 15, 2018
Collaborator

The PR is looking really good! I can feel the improvement when opening chats, but it seems to have a little inconsistency.

On the description you said that it is fetching a page of 40 messages, and here on the code I see 30, but the real issue is that when debbuging each time fetchMessages gets called I see 60 sections/messages being inserted on our list, so it seems to be doubling up this page size right here.

This comment has been minimized.

@rafaelks

rafaelks Oct 15, 2018
Author Contributor

@filipealva Just fixed the description of the PR to this number... where do you see 60? Can you point to the breakpoint you're using?

This comment has been minimized.

@filipealva

filipealva Oct 15, 2018
Collaborator

@rafaelks Initially I added the breakpoint inside RocketChatViewController's UIKit extension, inside the batch updates on line 45, then I print the changeset.sectionInserted property and it gives me 60 items, i.e. after doing the diffing there are 60 insertions.

Now I went back on it and tried to spot the same before the diffing, and I could manage to see the method func handle(insertions: [Int], on messagesQuery: Results<Message>) handling 60 items regularly.

It doesn't happens always, sometimes there are 20 insertions and another aleatory numbers, but if you keep testing you'll see that the most common number of insertions we have is 60 which is the double of the size we should be handling.

See the screenshot below:

screen shot 2018-10-15 at 16 12 28

This comment has been minimized.

@rafaelks

rafaelks Oct 15, 2018
Author Contributor

@filipealva I see... you're seeing the observer from Realm, so new results in database would result in all these new values, because the request we're doing it for 60 new messages. Good finding, I'll change the parameter to 30 for now. 👍

@codecov
Copy link

@codecov codecov bot commented Oct 15, 2018 •

Codecov Report

Merging #2253 into feature/integrate-rc-view-controller will decrease coverage by <.01%.
The diff coverage is 50%.

Impacted file tree graph

@@                           Coverage Diff                            @@
##           feature/integrate-rc-view-controller    #2253      +/-   ##
========================================================================
- Coverage                                 26.53%   26.53%   -0.01%     
========================================================================
  Files                                       423      423              
  Lines                                     15877    15878       +1     
========================================================================
  Hits                                       4213     4213              
- Misses                                    11664    11665       +1
Impacted Files Coverage Δ
...Managers/Model/MessageManager/MessageManager.swift 16.1% <ø> (ø) ⬆️
...cket.Chat/Controllers/Chat/MessagesViewModel.swift 39.74% <0%> (-0.02%) ⬇️
...Chat/Controllers/Chat/MessagesViewController.swift 38.7% <0%> (-3.23%) ⬇️
...t.Chat/Models/Subscription/SubscriptionUtils.swift 37.2% <100%> (+2.2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e96f1f...a606ab6. Read the comment docs.

Copy link
Collaborator

@filipealva filipealva left a comment

It's working beautifully! Really nice improvements 💯

Cycle 10: 10/05 ~ 11/05 automation moved this from In Progress to In Review / QA Oct 15, 2018
@filipealva filipealva merged commit abda423 into feature/integrate-rc-view-controller Oct 15, 2018
6 checks passed
6 checks passed
Hound No violations found. Woof!
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: test Your tests passed on CircleCI!
Details
codecov/patch 50% of diff hit (target 26.53%)
Details
codecov/project Absolute coverage decreased by -<.01% but relative coverage increased by +23.46% compared to 2e96f1f
Details
license/cla Contributor License Agreement is signed.
Details
Cycle 10: 10/05 ~ 11/05 automation moved this from In Review / QA to Done Oct 15, 2018
@filipealva filipealva deleted the improvement/datacontroller_improvements branch Oct 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.