Skip to content

fix: Apply SQLite optimizations to the custom connection_string in SqlStorageClient#1837

Open
Mantisus wants to merge 2 commits intoapify:masterfrom
Mantisus:optimization-sqllite
Open

fix: Apply SQLite optimizations to the custom connection_string in SqlStorageClient#1837
Mantisus wants to merge 2 commits intoapify:masterfrom
Mantisus:optimization-sqllite

Conversation

@Mantisus
Copy link
Copy Markdown
Collaborator

@Mantisus Mantisus commented Apr 5, 2026

Description

  • Since crawlee can have highly concurrent access to the database, SQLite optimizations must be applied, the most critical being journal_mode=WAL. If a user wants fine-grained control over connections, they should pass a custom engine instead of a 'connection_string'.

Issues

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Applies SQLite concurrency/performance pragmas (notably journal_mode=WAL) even when SqlStorageClient is configured via a custom SQLite connection_string, rather than only for the default database path.

Changes:

  • Replace the “default DB only” gate with a SQLite-specific optimization gate based on the provided connection_string.
  • Ensure SQLite pragmas are executed during initialization for SQLite connection strings when engine is not explicitly provided.
  • Update uv.lock metadata/options for dependency resolution reproducibility.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
uv.lock Adds uv lock options (exclude-newer, span) affecting how the lock was produced/resolved.
src/crawlee/storage_clients/_sql/_storage_client.py Expands SQLite pragma application to custom SQLite connection_string configurations (when engine is not provided).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Collaborator

@vdusek vdusek left a comment

Choose a reason for hiding this comment

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

LGTM, @Mantisus can I merge it? 🙂

# Flag needed to apply optimizations only for default database
self._default_flag = self._engine is None and self._connection_string is None
# Flag needed to apply optimizations only for SQLite database
self._optimization_flag = self._engine is None and (
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we instead set up an _on_connect callback here that would receive the new DB connection? That way, the logic (if sqlite, set up some pragmas) would be in one place.

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.

5 participants