lemmy
lemmy copied to clipboard
Remove unnecessary `PostActions::remove_like` call
When creating a new like, we first run a query to remove the existing like, if any. This should be completely unnecessary, we can set the new value with a single query. If the user is removing a previous vote this can be done with Some(None) like various other db forms. Similarly PersonActions::like should also be called only once.
With these changes the number of db write queries will be reduced by half for two of the most used api endpoints.
https://github.com/LemmyNet/lemmy/blob/45df25fcb8da9cdca1e93c011046ebd24cc7c0b1/crates/api/api/src/comment/like.rs#L70 https://github.com/LemmyNet/lemmy/blob/9d98c82ec30e8f261fd9459a4e75dc0f979de0eb/crates/apub/activities/src/voting/mod.rs#L78