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

[WIP] Paranet sync rework #3518

Open
wants to merge 1 commit into
base: release/v8.0.0-sigma
Choose a base branch
from

Conversation

brkagithub
Copy link
Contributor

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@brkagithub brkagithub changed the title wip (missing retry column) Paranet sync rework Dec 16, 2024
@brkagithub brkagithub changed the title Paranet sync rework [WIP] Paranet sync rework Dec 16, 2024
@@ -0,0 +1,60 @@
export async function up({ context: { queryInterface, Sequelize } }) {
await queryInterface.createTable('paranet_assets', {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Table should be named paranet_asset

type: Sequelize.STRING,
allowNull: false,
},
ual: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would make ual and paranet_ual as unique keys unique you can do it like this in raw SQL
ALTER TABLE `paranet_asset` ADD UNIQUE `unique_index`(`ual`, `paranet_ual`);

To prevent creation of duplicates

Copy link
Collaborator

Choose a reason for hiding this comment

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

```await queryInterface.sequelize.query(`...`);```

Copy link
Contributor

Choose a reason for hiding this comment

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

✅ Added this using queryInterface.addConstraint, like we had in finality_status

type: Sequelize.STRING,
allowNull: false,
},
public_assertion_id: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this

type: Sequelize.STRING,
allowNull: true,
},
private_assertion_id: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this

type: Sequelize.STRING,
allowNull: true,
},
sender: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't get this I think

type: Sequelize.DATE,
defaultValue: Sequelize.literal('NOW()'),
},
updated_at: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There needs to be a trigger for this, in raw SQL it is created like this:

        CREATE TRIGGER before_update_paranet_asset
        BEFORE UPDATE ON paranet_asset
        FOR EACH ROW
        SET NEW.updated_at = NOW();

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also add indexes on columns we do queries on:

Used to find missed assets

        CREATE INDEX idx_paranet_asset_updated_at_retries
        ON paranet_asset(updated_at, retries, isSynced);

Used to find all paranet assets

        CREATE INDEX idx_paranet_asset_paranet_ual_ual
        ON paranet_asset(ual, paranet_ual);

Not sure if we need any other indexes atm

Copy link
Collaborator

Choose a reason for hiding this comment

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

CREATE INDEX idx_paranet_asset_paranet_ual_syneced
        ON paranet_asset(synced, paranet_ual);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no need for first trigger, its done automatically by sequelize 99%, but will test it when i can

this.model = models.paranet_asset;
}

async createMissedParanetAssetRecord(missedParanetAsset, options) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to create missed reoced as all records are created when they are fetched, instead we should increment retry

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it's just stupid naming that i copied from before

return this.model.create({ ...missedParanetAsset, isSynced: false }, options);
}

async createParanetSyncedAssetRecord(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be createParanetAssetRecord

return this.model.count({
where: {
paranetUal,
isSynced: false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should also take into account retry to be less than constant and that updateAt + delay > current time

Copy link
Collaborator

Choose a reason for hiding this comment

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

Something like that is laready done on line 58

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we use both queries for different reasons i think

}

async getParanetSyncedAssetRecordsCountByDataSource(paranetUal, dataSource, options = {}) {
async getParanetSyncedAssetRecordsCountByDataSource(paranetUal, options = {}) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you change old function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we dont need this one at all, can remove it completely

Copy link
Contributor

Choose a reason for hiding this comment

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

✅ I checked, we have many now useless functions here, I commented those out and added 'TODO: remove'

@brkagithub brkagithub force-pushed the v8/paranet-sync-rework branch from e73f648 to 6dcabac Compare December 16, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants