Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

[Refactor] Use eventbus to propagate short link update to user short link repo #958

Open
Coteh opened this issue Jul 15, 2020 · 1 comment

Comments

@Coteh
Copy link
Collaborator

Coteh commented Jul 15, 2020

What is frustrating you?
When a user updates a short link in production, the update will automatically be reflected to the user short link table within PostgreSQL due to the ON UPDATE CASCADE trigger. Within unit tests however, in particular the updater_test suite, any tests that involve checking the user short link repository will not be reliable and may fail, due to the fact that the fake user link repo will not be updated. (The fake version does not benefit from the implicit SQL trigger)

In PR #938 a quick fix was implemented that updates the fake user short link repo when a short link is updated. However, this needs to be done more cleanly in the future. There are multiple repositories that link to short link repository by alias, and they should all be updated in a clean way.

Your solution
@byliuyang and I discussed utilizing https://github.com/short-d/eventbus as a way to solve this problem. The user short link repo can subscribe to the user short link update event using eventbus and be notified of any updates. Once it's notified of an update, it will be able to make the appropriate change to the user short link table.

Alternatives considered
In PR #938 I implemented a new method to the UserShortLink interface for updating the relation. This method is unimplemented for the SQL version because it doesn't need to be, while the method will be implemented for the fake version so that tests relying on this relation can pass.

I believe that this solution is also a viable one since there are no direct dependencies on the repositories themselves (it's using the dependencies that currently exist at the use case level) and thus we can opt to continue with this solution if the eventbus solution doesn't end up being as clear and concise.

edit: discussed with @byliuyang, this isn't the right way to go either. eventbus is currently looking like the best solution to the problem, as multiple repositories can be updated at once without writing lots of boilerplate application logic.

Additional context
This is one of the issues created as part of the refactor of short link business logic. (#938)

@arberiii
Copy link
Member

This issue is the same as issue 922, but this is way more detailed therefore I'm closing the other one.

I like the solution with the short-d/evenbus, however, I'm not sure how reliable it is. I think we need to test it before using it here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants