Skip to content

Conversation

@ibalosh
Copy link
Owner

@ibalosh ibalosh commented Oct 10, 2025

One of the fields returned from the API is reading_time. This is not a static field stored in the DB, rather a dynamic field calculated on request. We’d like to make reading_time into a static field stored on the posts table, and returned “normally” from the API.

  • Added migration, that will add new column to posts table
  • Added migration, backfill, that will update the reading_time column for existing posts
  • Updated Posts model, so that we calculate and save reading time to the posts table
  • Removed on-the-fly calculation of reading_time for property that is returned by API
  • Cleanup (test updates, better names etc)

next step (optional):

  • return null on API if there is no reading_time (empty string on front end)
  • this would change the response format, but just extend it so it should be fine

Notes

Migration

Everything is in one PR, however, release wise, this would be split up into multiple PR's in following order:

  1. migration - to add column to the table
  2. upgrade post model, so reading_time is stored in db for new posts, or saves
  3. migration - for backfill
    3.1 depending on the size of the table:
    3.1.1 small - do it with this sort of backfill
    3.1.2 big - probably a better choice to do the backfill by separately running the script, use API or SQL queries, to have better control over load on the DB
  4. remove on the fly calculation from extra-attrs and use real db column
  5. along the way update tests

Tests

Tests only run correctly in CI if PR is in Ghost.

@ibalosh ibalosh force-pushed the add-posts-reading-time branch from 9e9fb89 to 223dda6 Compare October 10, 2025 12:02
@ibalosh ibalosh changed the title Move reading time Move reading_time to posts table from being calculated on-the-fly Oct 10, 2025
@ibalosh ibalosh force-pushed the add-posts-reading-time branch from 223dda6 to 9ba2ed7 Compare October 10, 2025 13:21
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.

2 participants