-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor mini-tools #134
Refactor mini-tools #134
Conversation
🚀 🚀 |
For a performance boost
@@ -59,7 +59,7 @@ | |||
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") | |||
|
|||
# Use a different cache store in production. | |||
# config.cache_store = :mem_cache_store | |||
config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up — this'll need to be configured before deploying.
We're already using Rails.cache.fetch
. But it's not doing anything because no cache store is configured. This'll fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up. cc @Shpigford, we switched this over to Hatchbox recently correct?
@@ -0,0 +1,5 @@ | |||
class AddIndexForStockPriceTickers < ActiveRecord::Migration[8.0] | |||
def change | |||
add_index :stock_prices, :ticker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up — this migration will need to be ran after deploying. We're already fetching by ticker, and we're leaning into that even more in this PR. This'll make the queries quicker. Not that they'd absolutely need it now, but at some point they will.
Practically done here, just not comfortable marking it as ready because the stock portfolio backtest combobox search stopped working for me locally for some reason. It's also happening on Gonna be attending Rails World for the next couple of days, so I most likely won't be making progress until I'm back. But this is more than ready for feedback @zachgoll. |
@josefarias awesome, I'll take a read-through of this after I get my CSV imports overhaul done, which should line up pretty well with your return from Rails world! Have a good time, hoping to make it there one of these years :) |
@zachgoll I've figured out the search problem. Nothing to worry about, just local env trouble. Tests are passing locally but CI was failing this weekend. I think I've managed to address that but we'll need another CI run to make sure. Marking as ready now. Before deploying, I'd recommend:
|
@josefarias thanks for the helpful context and summary, looking through this now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, love the changes! Looked through the models / controllers / views pattern and it was super easy to follow as someone who hasn't looked at this codebase much, so hopefully the same holds true for new contributors :)
Left a few comments/questions, but I wouldn't let any of them hold this up. I did some manual QA and everything looked great.
app/views/tools/widgets/forms/_stock_portfolio_backtest.html.erb
Outdated
Show resolved
Hide resolved
@josefarias everything looks good here to me. Will let @Shpigford do the merging and bounty related stuff! Thanks again for the awesome work here! |
Always a pleasure @zachgoll, @Shpigford! I'll be available outside of work to troubleshoot any regressions, should they come up. Just pushed up some minor nit fixes, this is ready to merge. |
closes #133
This PR refactors the marketing site's mini-tools to follow Hotwire and Rails conventions.
Previously, the tools used a bespoke template rendering system instead of Hotwire (Turbo)'s built-in frames. Leveraging Hotwire makes the code:
<%= tool.inflation_rate %>
instead of<span t-text="inflationRate"></span>
)Also, all calculations were previously done on the client. They're now happening on the back-end. This makes the code:
Some JS cleanup was done in passing. But I decided not to make it a priority because the scope is already large enough and the existing code is not significantly breaking convention. There's room for improvement, but it's less crucial than the other problems addressed by this PR. That means there will still be work to be done on JS after merging. Most notably, the time series charts have not yet been refactored to be reusable — they remain coupled to specific tools.
Finally, I've removed code comments — which seem to have been added recently, and intentionally. I'm happy to bring those back, but I want to make the case that code comments add a maintainability burden in keeping them up to date. Ideally, the code should be readable enough that comments are mostly not necessary.
Important
This touches every single mini-tool. We should do some manual QA on every tool to ensure consistency.
Steps to add a new tool (for future reference)
db/seeds/tools.rb
bin/rails db:seed
app/presenters/tool
.#active_record
method to find their corresponding tool in the DB.app/views/tools/widgets
app/views/tools/widgets/forms
andapp/views/tools/widgets/content
. It's a nice pattern, but not mandatory.ToolsController#tool_params
.<%= tool.some_financial_indicator %>
<%= number_with_delimiter(tool.some_financial_indicator) %>
<%= number_to_currency(tool.some_financial_indicator) %>