danielpalme / MVCBlog

Blog engine based on ASP.NET Core 8 and Twitter Bootstrap 4
Apache License 2.0
244 stars 146 forks source link

TagRecords from Tags table not being removed when delete blogEntry #7

Closed Darth-Fx closed 7 years ago

Darth-Fx commented 7 years ago

When deleting a BlogEntry the EF will cascade delete the TagBlogEntries table but the Tags table isn't affected resulting in a lot of tag-orphans. This means that the Tags section (sidebar) is stil displaying the deleted Tags (effective after an hour or application restart).

I've fixed it by adding Tag deletion code in the HandleAsync of the DeleteBlogEntryCommandHandler but maybe I'm overlooking something.....

By the way, why the 3600 cacheduration on the sidebar? Great project!

danielpalme commented 7 years ago

The tags are cached for an hour and should then disappear:

https://github.com/danielpalme/MVCBlog/blob/master/src/MVCBlog.Website/Controllers/BlogController.cs#L212

Darth-Fx commented 7 years ago

If I just remove the Cache attribute and check, then the tags belonging to the deleted post are still visible.... But that's due to not clearing the tags of the deleted post from the DB:

https://github.com/danielpalme/MVCBlog/blob/master/src/MVCBlog.Core/Commands/BlogEntry/DeleteBlogEntryCommandHandler.cs#L19

If I include tags in this query [ .Include(c => c.Tags) ] , and remove them, then the tags are gone and not being rendered anymore.

danielpalme commented 7 years ago

Correct. But you have to be careful not to delete any tags that are used by other posts.