Currently, there is a direct one-to-one relationship between user
and employee
. In order to retrieve the data separately, I need to determine the most effective method for assigning each employee to their corresponding user. At the moment, I am using two nested forEach
loops (although I have discovered that this method is 96% slower than using a simple for
loop).
I am actively seeking a more optimized approach to handle this scenario. The variable ids
contains a list of user IDs. The goal is to match these IDs and assign the appropriate employee
to the corresponding user
.
this.employeeService.query({'userId.in': ids}).subscribe(employeeData => {
employeeData.body.forEach(employee => {
this.users.forEach(user => {
if (user.id === employee.userId) {
user.employee = employee;
}
});
});
});
Are there alternative methods you could suggest that may prove more efficient in achieving this task?