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

feat(db)!: Add a last-modified timestamp to each session. #731

Merged
merged 1 commit into from
Oct 20, 2022

Conversation

dhess
Copy link
Member

@dhess dhess commented Oct 19, 2022

Note that "modified" here means any edit, including session name changes. Read-only session queries don't update the timestamp.

BREAKING CHANGE: this change requires a database migration. If you want to preserve your existing local PostgreSQL database, you must run the deploy-local-db script against it. Assuming your PostgreSQL Docker container is running, run this:

nix run .#deploy-local-db

Closes #247
Closes https://linear.app/hackworthltd/issue/PRIM-20

@linear
Copy link

linear bot commented Oct 19, 2022

@dhess dhess requested a review from a team October 20, 2022 00:20
@dhess
Copy link
Member Author

dhess commented Oct 20, 2022

Sorry for the one massive commit. With database schema changes, there's no good way to stage the changes in multiple commits without breaking the build along the way.

README.md Show resolved Hide resolved
Comment on lines +267 to +269
-- We can revisit this if the performance impact of 'getCurrentTime'
-- becomes a problem.
now <- liftIO getCurrentTime
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have any references/data on the performance of getCurrentTime?

Copy link
Member Author

@dhess dhess Oct 20, 2022

Choose a reason for hiding this comment

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

I haven't looked into the details of how it's implemented in time, but I believe the general consensus is that reading the system's real-time clock is a relatively expensive operation. We would need to measure it for our specific case (our app, running on Fly.io, with a realistic load) to know for certain, hence the hedge.

I don't claim that this is representative of our case, but here is an example of how it can be problematic on EC2 instances:

https://careers.appian.com/blog/the-tech-corner/yet-another-reason-your-docker-containers-may-be-slow-on-ec2-clock_gettime-gettimeofday-and-seccomp/

@brprice
Copy link
Contributor

brprice commented Oct 20, 2022

Sorry for the one massive commit. With database schema changes, there's no good way to stage the changes in multiple commits without breaking the build along the way.

One thing that you could do is to split the code changes in two. One "plumbing" commit adding dummy arguments to constructors and functions, and one "useful" (much smaller) one that does the schema change and actually gets the current time etc. I'm not convinced how much easier to understand that would be though.

(In any case, I don't think it is worth changing this PR now)

Copy link
Contributor

@brprice brprice left a comment

Choose a reason for hiding this comment

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

Generally looks good. I have some minor comments/requests above though.

Note that "modified" here means any edit, including session name
changes. Read-only session queries don't update the timestamp.

BREAKING CHANGE: this change requires a database migration. If you
want to preserve your existing local PostgreSQL database, you must run
the `deploy-local-db` script against it. Assuming your PostgreSQL
Docker container is running, run this:

nix run .#deploy-local-db

Closes #247
Closes https://linear.app/hackworthltd/issue/PRIM-20
@dhess dhess enabled auto-merge October 20, 2022 11:48
@dhess dhess added this pull request to the merge queue Oct 20, 2022
@dhess
Copy link
Member Author

dhess commented Oct 20, 2022

Sorry for the one massive commit. With database schema changes, there's no good way to stage the changes in multiple commits without breaking the build along the way.

One thing that you could do is to split the code changes in two. One "plumbing" commit adding dummy arguments to constructors and functions, and one "useful" (much smaller) one that does the schema change and actually gets the current time etc. I'm not convinced how much easier to understand that would be though.

(In any case, I don't think it is worth changing this PR now)

I considered that, but figured that the work needed to shunt out the dummy values at the PostgreSQL interface would be extra work that in the very next commit would need to be ripped out, so decided against it.

Merged via the queue into main with commit 45c3037 Oct 20, 2022
@dhess dhess deleted the dhess/db-timestamps branch October 20, 2022 11:59
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.

Migration: add a last-modified column to sessions
2 participants