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

Improve SQLite default settings #9

Merged
merged 1 commit into from
Nov 2, 2024

Conversation

anze3db
Copy link
Contributor

@anze3db anze3db commented Nov 1, 2024

Hey! I really like your idea of simplifying the creation of new projects and I was wandering if you'd also like to add a better out of the box experience for SQLite.

The changes in the PR should make SQLite scale better in high concurrency environments (some benchmarks) and remove the most common SQLite gotchas.

I also want to propose the same change to Django's startproject template, but I figured it would be a good idea to try this out on your project first. Let me know what you think!

@epicserve
Copy link
Owner

I'm open to the idea, but I would need this added to the 4.1 template as well and then the code that auto updates the templates would need to be updated to add that change, or maybe a better approach would be to modify the code that creates the new project to make those changes to the new project files.

@anze3db
Copy link
Contributor Author

anze3db commented Nov 1, 2024

The init_command and transaction_mode options were only added in Django 5.1, so to get the same functionality in older Django versions we'd need to create our own DatabaseWrapper class. I'm happy to generate it as well if you think it's worth the extra hassle. Do you think there are people using dj-beat-drop to create new projects on older versions?

In any case, I'll move the change from the template to a python function called by create_new_project.

@epicserve
Copy link
Owner

Yeah, I don't think we need bother with adding it for older versions of Django. So you could add some logic to add if the version is greater than 5.1.

These settings make SQLite scale better in production environments with higher concurrency.
@anze3db anze3db force-pushed the improve-sqlite-settings branch from bd4f87d to bfcc317 Compare November 2, 2024 01:12
@@ -47,6 +67,7 @@
'SECRET_KEY="{{ secret_key }}"',
"ALLOWED_HOSTS=",
"DATABASE_URL=sqlite:///{{ project_dir }}/db.sqlite3",
"{% 5.1 %}" + SQLITE_OPTIONS_ENV,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

{% 5.1 %} feels like a hack, so please let me know if you have a better idea for running asserts based on the Django version.

@anze3db
Copy link
Contributor Author

anze3db commented Nov 2, 2024

@epicserve I've added the logic for both the env and non-env versions. Let me know if this works for you!

@epicserve epicserve merged commit bfcc317 into epicserve:main Nov 2, 2024
4 checks passed
@epicserve
Copy link
Owner

@anze3db,

I made a couple commits and merged. I switched to using a tuple instead of prefixing with the "{% 5.1 %}" string. It seemed a little better that way to me.

I also switched to using a constant for the options, so you only have to change it in one place.

Also when the options are in a URL, I made sure the options where URL encoded.

@anze3db anze3db deleted the improve-sqlite-settings branch November 2, 2024 23:45
@anze3db anze3db mentioned this pull request Nov 2, 2024
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