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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore old federated post edits (ref #4529) #4586

Merged
merged 6 commits into from
Apr 10, 2024
Merged

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented Apr 2, 2024

No description provided.

.map(|c| c.updated.unwrap_or(c.published))
.clone()
.ok();
verify_object_timestamp(old_timestamp, note.updated.or(note.published))?;
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately this is rather verbose, no way to avoid that unless we add a trait (which would be even more verbose and wouldnt be used anywhere else).

@dullbananas
Copy link
Collaborator

The timestamp should be checked by calling filter after set in each diesel upsert. Checking it separately in Object::verify is slower and doesn't work if multiple updates for the same object are processed at the same time.

If you don't want Object::from_json to return Err when the update is skipped, then it needs to ignore the diesel::result::Error::NotFound returned by the upsert.

@phiresky
Copy link
Collaborator

phiresky commented Apr 2, 2024

This looks generally fine to me, but I agree with dullbanas that filter the verify might not be the right place to do it?

To clarify on their second point, if you do it here you have a race condition where if two updates are processed simultaneously then the "verify" of the second can be called after the db update of the first, which then causes the older update to override the newer one.

The only guaranteed way to do this correctly is if the filtering happens as a WHERE in the update query.

@Nutomic
Copy link
Member Author

Nutomic commented Apr 3, 2024

Good suggestion, Ive changed it like that. Also added separate insert_apub() methods so that creates via api dont need to do upsert or timestamp check.

crates/db_schema/src/impls/comment.rs Outdated Show resolved Hide resolved
crates/db_schema/src/impls/comment.rs Outdated Show resolved Hide resolved
crates/db_schema/src/impls/community.rs Outdated Show resolved Hide resolved
crates/db_schema/src/impls/post.rs Outdated Show resolved Hide resolved
crates/db_schema/src/impls/private_message.rs Outdated Show resolved Hide resolved
.filter_target(coalesce(comment::updated, comment::published).lt(timestamp))
.do_update()
.set(comment_form)
.get_result::<Self>(conn)
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure but I think this will result in an error if the value is not updated? as in, the query will return zero rows which will cause get_result to return a row not found error unless you add .optional()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct

Copy link
Member Author

Choose a reason for hiding this comment

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

That should be fine, if we are receiving an old comment while already storing a newer one, it throws an error and gets rejected. We dont need to do anything in that case.

Copy link
Collaborator

@dullbananas dullbananas left a comment

Choose a reason for hiding this comment

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

Assuming @Nutomic is correct about returning an error when skipping update

@dessalines dessalines merged commit 0203b62 into main Apr 10, 2024
2 checks passed
@SleeplessOne1917 SleeplessOne1917 deleted the ignore-old-edits branch April 10, 2024 16:04
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.

None yet

5 participants