fredwu / bustle

Activities recording and retrieving using a simple Pub/Sub-like interface.
http://fredwu.github.com/bustle/
93 stars 8 forks source link

Publisher/Subscriber add should have find_or_create semantics #1

Open ches opened 12 years ago

ches commented 12 years ago

It's pretty icky to rely on unique indexes IMO, and a manifest symptom is a Rails log littered with transaction rollbacks. I know orm_adapter doesn't explicitly provide find_or_create (it would be unreasonable for it to support dynamic finders, after all), but it should be trivial to try get first instead of as a rescue for create! I think.

Thoughts? I could whip up a pull request with updated tests, but thought I'd make sure you're amenable to the idea first.

Pluggable persistence backends is a great goal to have for this, but in the long run I wonder if orm_adapter is really going to be of much use -- the stores that seem like the ideal targets (Redis and Mongo come to mind) have native Set data structures, which would be ideal to use.

fredwu commented 12 years ago

but it should be trivial to try get first instead of as a rescue for create! I think

Sure! I don't have a strong opinion on this one so I'm happy for you to change this behaviour. :)

the stores that seem like the ideal targets (Redis and Mongo come to mind) have native Set data structures, which would be ideal to use

I agree. Though we might not need those datastores anytime soon. I imagined that we could rely on AR for quite a while, especially when I get the pagination sorted. :)