Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/crawlee/_utils/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ def compute_short_hash(data: bytes, *, length: int = 8) -> str:

def crypto_random_object_id(length: int = 17) -> str:
"""Generate a random object ID."""
chars = 'abcdefghijklmnopqrstuvwxyzABCEDFGHIJKLMNOPQRSTUVWXYZ0123456789'
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
return ''.join(secrets.choice(chars) for _ in range(length))
17 changes: 8 additions & 9 deletions src/crawlee/storage_clients/_sql/_request_queue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import TYPE_CHECKING, Any, cast

from sqlalchemy import CursorResult, exists, func, or_, select, update
from sqlalchemy import func as sql_func
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm import load_only
from typing_extensions import NotRequired, Self, override
Expand Down Expand Up @@ -778,22 +777,22 @@ def _prepare_buffer_data(
@override
async def _apply_buffer_updates(self, session: AsyncSession, max_buffer_id: int) -> None:
aggregations: list[ColumnElement[Any]] = [
sql_func.max(self._BUFFER_TABLE.accessed_at).label('max_accessed_at'),
sql_func.max(self._BUFFER_TABLE.modified_at).label('max_modified_at'),
sql_func.sum(self._BUFFER_TABLE.delta_handled_count).label('delta_handled_count'),
sql_func.sum(self._BUFFER_TABLE.delta_pending_count).label('delta_pending_count'),
sql_func.sum(self._BUFFER_TABLE.delta_total_count).label('delta_total_count'),
func.max(self._BUFFER_TABLE.accessed_at).label('max_accessed_at'),
func.max(self._BUFFER_TABLE.modified_at).label('max_modified_at'),
func.sum(self._BUFFER_TABLE.delta_handled_count).label('delta_handled_count'),
func.sum(self._BUFFER_TABLE.delta_pending_count).label('delta_pending_count'),
func.sum(self._BUFFER_TABLE.delta_total_count).label('delta_total_count'),
]

if not self._had_multiple_clients:
aggregations.append(
sql_func.count(sql_func.distinct(self._BUFFER_TABLE.client_id)).label('unique_clients_count')
func.count(func.distinct(self._BUFFER_TABLE.client_id)).label('unique_clients_count')
)

if self._storage_client.get_dialect_name() == 'postgresql':
aggregations.append(sql_func.bool_or(self._BUFFER_TABLE.need_recalc).label('need_recalc'))
aggregations.append(func.bool_or(self._BUFFER_TABLE.need_recalc).label('need_recalc'))
else:
aggregations.append(sql_func.max(self._BUFFER_TABLE.need_recalc).label('need_recalc'))
aggregations.append(func.max(self._BUFFER_TABLE.need_recalc).label('need_recalc'))

aggregation_stmt = select(*aggregations).where(
self._BUFFER_TABLE.storage_id == self._id, self._BUFFER_TABLE.id <= max_buffer_id
Expand Down
Loading