Re:Domain Driven Design When Surrounded by Legacy Developmen...
by marktangotango on Tuesday February 17, 2015 @01:35PM
(#9064069)
This is heresy and unbelievers will be punished! Seriously though, I agree whole heartedly and am often dismayed at the lengths developers will go through to not write sql.
Re:Domain Driven Design When Surrounded by Legacy Developmen...
by vinceguidry on Tuesday February 17, 2015 @02:19PM
(#9064363)
Oh believe me, I tried to use Sequel to get that data. After I realized just how many joins and how many layers of abstraction I'd need to debug the damn thing through, I knuckled down and built the query. Even so it runs behind a caching layer. Thankfully, I don't need up-to-the-minute product data.
Re:Domain Driven Design When Surrounded by Legacy Developmen...
by marktangotango on Tuesday February 17, 2015 @02:27PM
(#9064406)
At one previous gig we had a product-god query similar to what you're describing, which was the source of neverending sorrow. Eventually, the solution was to write and schedule a stored procedure that built a 'current_product' table with essential fields. Products and catalogs weren't updated that frequently, so it ran nightly, or could be run on demand. Performance increase was immense.
Re:Domain Driven Design When Surrounded by Legacy Developmen...
by vinceguidry on Tuesday February 17, 2015 @02:41PM
(#9064481)
My problem was that there was so much baked in logic that I had to trace through the codebase to figure out, and even so, I was getting lots of incorrect results for months until I'd worked all the issues out. Even now sometimes my boss will be like, "there's bad data in the feed, can you check the query?" Most of the time it's bad data, but every time I have to load the damn query up in SequelPro and make sure it's doing its job. I dread the day when I actually have to understand what it's doing again.
When I first got to the job I thought it might be worthwhile to refactor and upgrade the old codebase, but eventually settled on the cordon strategy because it's ultimately more flexible, and not having to touch the production site every day gives me a lot of peace of mind.
Anyone in this situation, I would recommend re-implementing your Active Record models with an external database connection using Sequel or even just regular SQL queries. I have a giant query with a crapload of joins that can retrieve product data, it's among the very first things I built at this job.
This provides a nice base to build on, the database is the heart and soul of the business, and it is far easier to work at that level of abstraction rather than trying to mess around inside the codebase.