lemmy icon indicating copy to clipboard operation
lemmy copied to clipboard

Removing post url doesnt federate (ref #4372)

Open Nutomic opened this issue 2 years ago • 4 comments

Post url should be removed by setting it to Some(None) on PostUpdateForm. But for federation we use PostInsertForm as there is no way to distinguish between insert and update. The insert form doesnt allow setting Some(None), only Some(url) or None. So there is currently no way to set the url to null. Not sure whats the best way to fix this. The same problem might affect other fields as well.

Nutomic avatar Jan 15 '24 11:01 Nutomic

This can be fixed by updating using a tuple with post::column_name.eq(excluded(post::column_name)) for each column.

https://docs.rs/diesel/latest/diesel/upsert/fn.excluded.html

https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT

This also makes it possible to later implement batched upserts because all rows use the same expressions for the update.

dullbananas avatar Jan 15 '24 13:01 dullbananas

@dullbananas That doesnt sound correct, after all its valid to change the post url to a different one. But maybe you can implement it and see if it passes the tests.

Nutomic avatar Jan 22 '24 10:01 Nutomic

@Nutomic I don't see why it would prevent changing the url. excluded gets the new row, not the old row.

dullbananas avatar Jan 22 '24 12:01 dullbananas

Okay I understood it now and implemented that. There are two problems:

  • Its easy to forget adjusting the Post::update function when new fields are added, so maybe it should be done with a macro
  • As the fields are overwritten unconditionally, it means that embed fields are wiped when receiving a federated edit

Nutomic avatar Jan 22 '24 16:01 Nutomic