-
Notifications
You must be signed in to change notification settings - Fork 75
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
base: release/v8.0.0-sigma
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,60 @@ | |||
export async function up({ context: { queryInterface, Sequelize } }) { | |||
await queryInterface.createTable('paranet_assets', { |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```await queryInterface.sequelize.query(`...`);```
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 = {}) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'
e73f648
to
6dcabac
Compare
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.
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
Checklist: