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

feat: Retry fetching missing user/conversation metadata every 3h (FS-1691) #15158

Merged
merged 9 commits into from
May 11, 2023

Conversation

thisisamir98
Copy link
Contributor

@thisisamir98 thisisamir98 commented May 11, 2023

Sub-taskFS-1691 [web] Retry fetching missing user/conversation metadata every 3h

Scenario:

  • Backend A & B are federated.
  • User X from A & User Y from B are in a conversation.
  • Connection between A & B goes offline.
  • User X does a fresh login with no previous data on its local database.

Issue:

At this point user X is unable to fetch the meta data of user Y because the data lives on the B backend and connection is offline.

Solution

@atomrc Has already implemented a try to refetch that missing meta data when opening the user details menu here:
#14975

This PR will add another solution to this issue to try to refetch all missing data every 3 hours.

Copy link
Contributor

@V-Gira V-Gira left a comment

Choose a reason for hiding this comment

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

Looking good! 💪

Comment on lines 472 to 475
const allUnavailableUsers: User[] = [];
this.conversationState.conversations().forEach(conversation => {
allUnavailableUsers.push(...conversation.allUserEntities().filter(user => !user.isAvailable()));
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why no .map()? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -291,6 +291,7 @@ export class ConversationRepository {

this.conversationRoleRepository = new ConversationRoleRepository(this.teamRepository, this.conversationService);
this.leaveCall = noop;
this.scheduleMissingUsersAndConversationsMetadataRefresh();
Copy link
Contributor

Choose a reason for hiding this comment

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

if this is supposed to be federation only, why isn't it conditional at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no missing data so we'll iterate over an empty array and no request will be fired, but still we could add a isFederated check to avoid that as well but performance wise that's micro optimization

Copy link
Contributor

@tlebon tlebon May 11, 2023

Choose a reason for hiding this comment

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

is there no way to tell we are in a federated environment? i dont see why we should run a bunch of async calls every 3 hours if we dont need to. (regardless of performance impact)

Copy link
Contributor

@PatrykBuniX PatrykBuniX May 11, 2023

Choose a reason for hiding this comment

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

maybe this.core.backendFeatures.isFederated? @thisisamir98

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -100,6 +100,8 @@ describe('ConversationRepository', () => {
};

beforeAll(async () => {
jest.useFakeTimers();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this somehow breaking some other test cases? The ci is breaking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe, i'm checking...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tlebon
Copy link
Contributor

tlebon commented May 11, 2023

please fill out the PR info

@codecov
Copy link

codecov bot commented May 11, 2023

Codecov Report

Merging #15158 (6270ce7) into dev (6d377c5) will increase coverage by 0.04%.
The diff coverage is 92.30%.

@@            Coverage Diff             @@
##              dev   #15158      +/-   ##
==========================================
+ Coverage   43.15%   43.20%   +0.04%     
==========================================
  Files         644      644              
  Lines       21634    21647      +13     
  Branches     4954     4956       +2     
==========================================
+ Hits         9337     9353      +16     
+ Misses      11105    11102       -3     
  Partials     1192     1192              

Comment on lines 487 to 489
if (!this.core.backendFeatures.isFederated) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

if we do nothing in this case, maybe let's just not call this function at all, so wrap it with the condition:

if(this.core.backendFeatures.isFederated){
  scheduleMissingUsersAndConversationsMetadataRefresh()
}

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -467,6 +468,35 @@ export class ConversationRepository {
await this.userRepository.refreshUsers(unavailableUsers.map(user => user.qualifiedId));
}

public async refreshAllConversationsUnavailableParticipants(): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this one to be public since it's being used only in this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the other one (refreshUnavailableParticipants) implemented previously by @atomrc was public so I made this public as well but we could make it private.

@thisisamir98 thisisamir98 merged commit 735e7b3 into dev May 11, 2023
@thisisamir98 thisisamir98 deleted the feat/FS-1691 branch May 11, 2023 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants