this post was submitted on 07 Aug 2023
10 points (100.0% liked)

Rust Programming

7734 readers
1 users here now

founded 5 years ago
MODERATORS
 

In lemmy_server, at this code point: https://github.com/LemmyNet/lemmy/blob/91c024fd987b61ac8892b9e7d1896ee4574751da/crates/db_schema/src/impls/comment.rs#L62

How would I determine if it was an SQL UPDATE or INSERT and skip the remaining blocks of code that do work that does not need to be repeated when a comment edit (UPDATE) is being performed.

Thank you.

top 1 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

Before the upsert, do a select where the result is optional. Then if_some() it was an update, if_none() it was an insert.

Looks like the on_conflict is on the ap_url, so I would use that as the key you're trying to pull in the select.