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

Optimize message status updates #159

Merged
merged 3 commits into from
Apr 11, 2022
Merged

Optimize message status updates #159

merged 3 commits into from
Apr 11, 2022

Conversation

mirgee
Copy link
Contributor

@mirgee mirgee commented Apr 7, 2022

Currently, message handling of type UPDATE_MSG_STATUS_BY_CONNS is highly inefficient. It takes a list of pairs of pwDids of the agent connection corresponding to the message to be updated and a list of uids of the messages to be updated (along with the status code to be assigned):

[{"pairwiseDID":"Fp4eVWcjyRawjNWgnJmJWD","uids":["b7vh36XiTe"]}]

In order to perform the update, this argument is converted to a format such that each agent connection pwDid is converted to an agent connection did, querying the database potentially multiple times in the process.

Moreover, in order to construct the response containing updated and failed-to-update lists of pairs in the same format described above, it performs an inverse conversion using the same inefficient method described above.

This PR optimizes this behavior in a weakly backwards-compatible fashion by ensuring global uniqueness of message uids on the database level (by using UNIQUE constraint), merging all the uids in the received messages and performing a single query on indexed columns agent_did and uid on the messages table.

Signed-off-by: Miroslav Kovar [email protected]

@mirgee mirgee force-pushed the feature/update-msg-opt branch 6 times, most recently from 8526ad9 to 713df68 Compare April 7, 2022 19:52
Signed-off-by: Miroslav Kovar <[email protected]>
@mirgee mirgee marked this pull request as ready for review April 7, 2022 20:11
@mirgee mirgee requested a review from Patrik-Stas April 7, 2022 20:11
@Patrik-Stas
Copy link
Contributor

Patrik-Stas commented Apr 8, 2022

Please add PR description of this, formally, breaking change.

@Patrik-Stas
Copy link
Contributor

Patrik-Stas commented Apr 8, 2022

In test

agent-msgs.spec.js /  "should update statusCodes of messages"

Lets change

    const uidsByConn = [
      { pairwiseDID: aconn1UserPwDid, uids: [msg1Id, msg2Id] },
      { pairwiseDID: aconn2UserPwDid, uids: [msg6Id] }
    ]

to something like

    const uidsByConn = [
      { pairwiseDID: "not-taken-in-consideration", uids: [msg1Id, msg2Id] },
      { pairwiseDID: "not-taken-in-consideration", uids: [msg6Id] }
    ]

to signal that pairwiseDID makes not difference anymore.

Copy link
Contributor

@Patrik-Stas Patrik-Stas left a comment

Choose a reason for hiding this comment

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

left comments

Signed-off-by: Miroslav Kovar <[email protected]>
@mirgee mirgee added the enhancement New feature or request label Apr 8, 2022
@mirgee mirgee requested a review from Patrik-Stas April 8, 2022 13:11
@Patrik-Stas Patrik-Stas merged commit 250acf6 into master Apr 11, 2022
@Patrik-Stas Patrik-Stas deleted the feature/update-msg-opt branch April 11, 2022 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants