⚠️ This post links to an external website. ⚠️
Let's say you want to store a map in an
Ecto.Schema. You add a:mapfield which Ecto converts into an optimizedjsonbcolumn in Postgres. You trust the awesomeness of Postgres and start dumping data into it. Everything works fine.Until your PM pings you.
Hey. Why is our website so slow now?Weird.
Everything works fine locally, but your production website now takes seconds to load when it worked just fine yesterday. You scratch your head. Is it maybe the new
:mapfield you added?Spoiler: It is! 🎉
You realize that only pages that list many records are affected and pages that show a single record are not. Then it hits you:
jsonbfields can hold up to~268MBof data andjsonfields even up to1GB! Whenever you list your records, Ecto fetches all this data from the database. Most times, you don't even need it!So, how can you tell Ecto to not load it by default?
continue reading on peterullrich.com
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.