Skip to content
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

4727 replace redis with solidcache #4929

Merged
merged 10 commits into from
Jan 21, 2025

Conversation

coalest
Copy link
Collaborator

@coalest coalest commented Jan 17, 2025

Resolves #4727

Description

Removes dependency on redis, and configures solid_cache to use postgres as a cache store.

Type of change

  • Infrastructure

How Has This Been Tested?

I've tested the app in production mode on my local computer, and confirmed that caching is still working.

This change wouldn't be caught by our test suite so we need to be careful.

Also db:prepare needs to run after this change is merged in production in order to create the caching table in postgres. If the cache schema isn't loaded, then we will get an error every time we try to access the cache store (like on the historical trends pages).

@@ -1,6 +1,5 @@
development:
adapter: redis
url: redis://localhost:6379/1
adapter: async
Copy link
Collaborator Author

@coalest coalest Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we were using redis in dev but async in staging/prod previously as the adapter for Action Cable.

I think we are only using Action Cable for turbo streams atm.

Note: async isn't recommended for production. So we may want to switch to the action cable postgres adapter, or to solid_cable at some point.

default: &default
store_options:
# Cap age of oldest cache entry to fulfill retention policies
max_age: <%= 14.days.to_i %>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This max_age is the default if you don't set it. I don't think it matters at this point because the only caching we currently do for historical trends is updated every 24 hours.

But we can make it 30 or 60 days if preferred.

@coalest coalest requested a review from dorner January 17, 2025 14:10
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this, but a bit fuzzy on the rollout plan.

password: <%= ENV["DIAPER_DB_PASSWORD"] %>
database: <%= ENV["DIAPER_DB_DATABASE"] %>
timeout: 5000
cache:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're creating a separate database... that needs a script or migration to be run, correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All I had to run (with my env set to production) was db:prepare and that created the solid cache database and created the cache table.

I haven't really looked into the inner workings of how the database is created and table schema loaded.

I assume the deployment process for production has a db:migrate step but i dont think that will be enough in this case. Will double check tomorrow

Copy link
Collaborator Author

@coalest coalest Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea so db:prepare in this case creates the cache database and then loads the cache table from the new schema file db/cache_schema.rb. It would also run any pending migrations, but there aren't any for this new cache table, just the schema to load.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coalest can you look to see if we can use the same database instead of 2 different ones? I know the docs seem to favor a separate DB, but it would simplify migration if we could just create a table in the existing DB.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I believe using the same database should be fine. I will make that change.

Copy link
Collaborator Author

@coalest coalest Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8b116b6.

All that will be needed for produciton is to run db:migrate. I tested this locally (with environment set to production) and caching is working as expected.

@coalest coalest requested a review from dorner January 21, 2025 11:40
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good - I'm excited!

@cielf can we make sure we test the historical cache job on staging before we deploy?

@dorner dorner merged commit 97254a3 into rubyforgood:main Jan 21, 2025
11 checks passed
Copy link
Contributor

@coalest: Your PR 4727 replace redis with solidcache is part of today's Human Essentials production release: 2025.01.22.
Thank you very much for your contribution!

@coalest coalest deleted the 4727-replace-redis-with-solidcache branch January 26, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace redis with solidcache
2 participants