Philipp Hörist pushed to branch master at gajim / gajim
Commits:
55c02cb7 by mesonium at 2025-03-20T20:11:30+01:00
fix: Storage: Fix error on big queries
Add new decorator which also returns a iterator
Fixes #12148
- - - - -
2 changed files:
- gajim/common/storage/archive/storage.py
- gajim/common/storage/base.py
Changes:
=====================================
gajim/common/storage/archive/storage.py
=====================================
@@ -53,6 +53,7 @@
from gajim.common.storage.base import timeit
from gajim.common.storage.base import VALUE_MISSING
from gajim.common.storage.base import with_session
+from gajim.common.storage.base import with_session_yield_from
from gajim.common.util.datetime import FIRST_UTC_DATETIME
from gajim.common.util.text import get_random_string
@@ -744,8 +745,7 @@ def get_message_stanza_ids_from_occupant(
result = cast(Sequence[str] | None, session.scalars(stmt).all())
return result
-
- @with_session
+ @with_session_yield_from
@timeit
def search_archive(
self,
@@ -1117,7 +1117,7 @@ def cleanup_chat_history(self, session: Session) -> None:
log.info('Removed messages older then %s', threshold.isoformat())
- @with_session
+ @with_session_yield_from
@timeit
def get_messages_for_export(
self, session: Session, account: str, jid: JID
=====================================
gajim/common/storage/base.py
=====================================
@@ -19,6 +19,7 @@
import sys
import time
from collections.abc import Callable
+from collections.abc import Iterator
from datetime import datetime
from datetime import UTC
from pathlib import Path
@@ -439,7 +440,6 @@ def shutdown(self) -> None:
del self._session
del self._engine
-
def with_session(
func: Callable[Concatenate[Any, Session, P], R]
) -> Callable[Concatenate[Any, P], R]:
@@ -449,6 +449,15 @@ def wrapper(self: Any, *args: P.args, **kwargs: P.kwargs)
-> R:
return wrapper
+def with_session_yield_from(
+ func: Callable[Concatenate[Any, Session, P], Iterator[R]]
+) -> Callable[Concatenate[Any, P], Iterator[Any]]:
+ def wrapper(self: Any, *args: P.args, **kwargs: P.kwargs) -> Iterator[R]:
+ with self._create_session() as session, session.begin():
+ yield from func(self, session, *args, **kwargs)
+
+ return wrapper
+
class JIDType(sa.types.TypeDecorator[JID]):
impl = sa.types.TEXT
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/55c02cb7e1f378ef856be419e2b327bf20811ac6
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/55c02cb7e1f378ef856be419e2b327bf20811ac6
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]