Removing post url doesnt federate (ref #4372)
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.
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 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 I don't see why it would prevent changing the url. excluded gets the new row, not the old row.
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