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

Build listener to backfill position #4432

Merged
merged 2 commits into from
Mar 13, 2024
Merged

Conversation

thomtrp
Copy link
Contributor

@thomtrp thomtrp commented Mar 12, 2024

We want the position set for all our records.
Currently, this is still possible to create records without a position through the rest API.

This PR:

  • adds a listener that listens on all record creations and trigger a job if the position is not set
  • a job that simply call a new record position backfill service
  • the service that backfill the position

I re-used the existing logic that overrides the position in the args during a normal creation through web. I put it in a new factory RecordPositionFactory.

TODO:

  • testing once the strategy is validated

private readonly recordPositionQueryFactory: RecordPositionQueryFactory,
) {}

async create(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simply moved the logic of buildPositionValue in there

providers: [
WorkspaceQueryRunnerService,
...workspaceQueryRunnerFactories,
RecordPositionListener,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@charlesBochet @magrinj I don't know if the service / job / factory / listener should live into the query runner folder. Is there a better place ?

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

Left a few comments @thomtrp

recordId?: string,
): Promise<string> {
const name =
(objectMetadata.isCustom ? '_' : '') + objectMetadata.nameSingular;
Copy link
Member

Choose a reason for hiding this comment

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

nit: We should probably have a helper for that for when we will remove this logic

dataSourceSchema: string,
recordId: string,
): Promise<string> {
return `UPDATE ${dataSourceSchema}."${name}"
Copy link
Member

Choose a reason for hiding this comment

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

prepared statements would be safer

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

LGTM

@thomtrp thomtrp merged commit 7b63cf1 into main Mar 13, 2024
15 checks passed
@thomtrp thomtrp deleted the tt-build-position-listener branch March 13, 2024 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants