Categories: Technology

by Incrust Software

Share

Problem

We take Input from the Users who upload the Images and Videos which we refer to as Assets.

There is a requirement where the user also known as Creator needs to upload these Assets and submit them to the next User who is known as the Reviewer.

The submission of the Assets to the Reviewer is in the form where there are multiple Creators and multiple Reviewers but the Asset submitted by the Creator should be assigned to the Reviewer in Round Robin Format.

Example of Round Robin

Suppose there are 4 creators and 3 Reviewers and the Creators submit the Assets and they should get assigned as below

Creator1 submits Assets it goes to Reviewer1

Creator2 submits Assets it goes to Reviewer2

Creator3 submits Assets it goes to Reviewer3

Creator4 submits Assets it will go to Reviewer1

So it should follow the above structure for Assignment of Assets to Reviewer.

The issue here is that suppose there are 100 Assets related to one Request which Creator sends to the Reviewer.

So Reveiwer1 gets 100 Assets Assigned.

Similarly,

Reviewer2 gets 50 Assets assigned with the next Request.

For example

Creator1 -> 100 Assets-> RequestId1 -> Reviewer1

Creator2-> 50 Assets-> RequestId2-> Reviewer2

Creator3->10 Assets-> RequestId3-> Reviewer3

Creator4->20 Assets-> RequestId4->Reviewer1

The code implemented for this was to take RequestId as input and apply the for loop and traverse each Asset within it and assign it to the respected Reviewer by checking the flag assigned to the Reviewer whether it is true or false and applying the Round Robin format.

This code had problems as it was taking much time to assign the Reviewers to Assets and was consuming a lot of memory which caused the other users to wait and the site was not getting loaded too.

The solution to the above Problem

The solution applied to the above problem was by taking the RequestId and instead of applying a loop and traversing each Asset one by one, we applied a loop to group the Assets related to each Request and assign the Reviewer to Request at once by updating the records in bulk using the query as below:

A query to fetch the data

“select RequestId, AssetId from Assets where AssetId in (‘” + Array + “‘)”

A query to check whether the Request is already been assigned to a Reviewer

“Select ReviewerId from Request where RequestId='” + ArrayJson[i].RequestId + “‘”

And if it is already assigned a Reviewer then update the Request using a query as

Update Assets set ReviewerId='” + resultRequestSelect[0][0].ReviewerId + “‘,Status=’Pending Reviewer’ where RequestId='” +ArrayJson[i].RequestId + “‘ and AssetId in (‘”+AssignAsset+”‘)

Where AssignAsset is an Array of Assets that have been grouped for that particular Request

And suppose if that Request is not assigned any Reviewer yet then fetch the Reviewer whose flag is set to false and assign that Reviewer that particular Request with the code below

Select the flag with a false value and the respective ReviewerId as

Select flag, ReviewerId from Users where Active='” + 1 + “‘ and RoleId='” + 2 + “‘ and flag='” + 0 + “‘ order by ReviewerId”

And now update the table with the records with the code below

“Update Request set ReviewerId='” + ReviewerId + “‘ where RequestId='” + RequestId + “‘

And do set the flag to true so that we can fetch another Reviewer in Round Robin Format

At a certain point, all flags would be set to true and there comes a situation where there are no flags set to false so in this case check a flag where if all are false then set all flags to true and follow the same process to assign Reviewer and set the flag to false.

Conclusion

So, using this solution reduced memory consumption and time efficiency was much better as compared to the code first implemented. It also solved the issue of loading the site where the user need not wait after login and was easily able to perform the operations he needed.

Hope this solution solves the issue if this matches the problem you are searching for.

STAY IN THE LOOP

Subscribe to our free newsletter.

Related Posts

View all
  • What is the Bet Stop and How does Bet Stop – the National Self-Exclusion Register™ work?   Bet Stop – the National Self-Exclusion Register™ is a safe and free Australian Government initiative to block yourself from all licensed Australian online and phone gambling providers in a single process. You can register at any time and you […]

    Continue reading
  • Websites are always prone to security risks. This may impact businesses. Strengthen your web portal’s security. Read through our article for some problems and actionable solutions to ensure your web portal is secured OpenSSL 1.1 is considered outdated and vulnerable Issue a new SSL certificate (CA) and update it in your apache SSL configuration file. […]

    Continue reading
  • Continue reading
  • Continue reading