Skip to content

[IMPROVE] Improve performance and remove agents when the department is removed#17049

Merged
sampaiodiego merged 18 commits intodevelopfrom
fix-livechat-department-agents
Jul 21, 2020
Merged

[IMPROVE] Improve performance and remove agents when the department is removed#17049
sampaiodiego merged 18 commits intodevelopfrom
fix-livechat-department-agents

Conversation

@MarcosSpessatto
Copy link
Copy Markdown
Contributor

Improved LiveChat department agents query performance and removed agents when the department is removed.

@renatobecker renatobecker modified the milestones: 3.2.0, 3.1.0 Mar 28, 2020
Copy link
Copy Markdown
Contributor

@renatobecker renatobecker left a comment

Choose a reason for hiding this comment

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

@MarcosSpessatto The client-side, for instance, the LivechatDepartmentForm need to stop using the 3rd parameter of the method Livechat.saveDepartment, we need to stop using the departmentAgents parameter here:

saveDepartment(_id, departmentData, departmentAgents) {
, the agents need to be inserted/removed to departments by using a specific method and REST API method for that, so you can control this on the client, for example, when an agent is added, you can create a specific var to store it until the user clicks to save. The same can be done when an agent is deleted. Then, you can apply these changes after the user save the department, did you get it?
The current implementation is overriding the agents of the departments based on the data passed through that parameter, but to give you an example, the Livechat Department form fetches the agents through the REST API with pagination. So, when the department is saved, only those agents passed to the parameter will be affected, which means that if the department has 1k agents and the client sent just the data related to the existing agents on the client-side, the other agents in the collection won't be affected, did you get it?
And there is one more thing: this code is considering only users passed to the parameter agents, and this part of the code is considering this also, so any other existing agents in the collection will be removed.
To fix this, the client needs to add/remove agents through the REST API methods instead of passing changes related to the agents through the method parameters.

Also, we need to remove this process from this part of the code

const savedAgents = _.pluck(LivechatDepartmentAgents.findByDepartmentId(_id).fetch(), 'agentId');
const agentsToSave = _.pluck(agents, 'agentId');
// remove other agents
_.difference(savedAgents, agentsToSave).forEach((agentId) => {
LivechatDepartmentAgents.removeByDepartmentIdAndAgentId(_id, agentId);
});
. To remove agents, we need to use a specific method to perform it, even though we still support creating departments with default agents, like through the REST API method.

@renatobecker
Copy link
Copy Markdown
Contributor

renatobecker commented Apr 17, 2020

@MarcosSpessatto can you please fix the conflicts?
Thanks.

@engelgabriel engelgabriel modified the milestones: 3.1.0, 3.2.0 Apr 20, 2020
@MarcosSpessatto MarcosSpessatto modified the milestones: 3.2.0, 3.3.0 May 4, 2020
@renatobecker
Copy link
Copy Markdown
Contributor

@MarcosSpessatto can you please the conflicts?
Then I can finish the review process and merge it.

Thanks.

@renatobecker renatobecker modified the milestones: 3.3.0, 3.4.0 May 21, 2020
@renatobecker renatobecker modified the milestones: 3.4.0, 3.5.0 Jun 21, 2020
@sampaiodiego sampaiodiego merged commit 30acaef into develop Jul 21, 2020
@sampaiodiego sampaiodiego deleted the fix-livechat-department-agents branch July 21, 2020 03:42
@sampaiodiego sampaiodiego mentioned this pull request Jul 28, 2020
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.

4 participants