From 5fc1bd2d4032f600401e98111679e579c71187ec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:34:41 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pycrdt_websocket/ystore.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pycrdt_websocket/ystore.py b/pycrdt_websocket/ystore.py index a0ca310..1842d42 100644 --- a/pycrdt_websocket/ystore.py +++ b/pycrdt_websocket/ystore.py @@ -9,7 +9,7 @@ from inspect import isawaitable from logging import Logger, getLogger from pathlib import Path -from typing import AsyncIterator, Awaitable, Callable, cast, Literal +from typing import AsyncIterator, Awaitable, Callable, Literal, cast import anyio from anyio import TASK_STATUS_IGNORED, Event, Lock, create_task_group @@ -488,7 +488,8 @@ async def write(self, data: bytes) -> None: squashed = False if (self.document_ttl is not None and newest_diff > self.document_ttl) or ( - self.history_length is not None and oldest_diff > self.min_cleanup_interval + self.history_length + self.history_length is not None + and oldest_diff > self.min_cleanup_interval + self.history_length ): # squash updates ydoc = Doc() @@ -501,7 +502,8 @@ async def write(self, data: bytes) -> None: ydoc.apply_update(update) # delete older history await cursor.execute( - "DELETE FROM yupdates WHERE path = ? AND timestamp < ?", (self.path, older_than) + "DELETE FROM yupdates WHERE path = ? AND timestamp < ?", + (self.path, older_than), ) # insert squashed updates squashed_update = ydoc.get_update() @@ -524,11 +526,14 @@ async def write(self, data: bytes) -> None: await self._db.commit() await cursor.execute("VACUUM") - async def _get_time_differential_to_entry(self, cursor, direction: Literal["ASC", "DESC"] = "DESC") -> float: - """ Get the time differential to the newest (DESC) or oldest (ASC) entry in the database. """ + async def _get_time_differential_to_entry( + self, cursor, direction: Literal["ASC", "DESC"] = "DESC" + ) -> float: + """Get the time differential to the newest (DESC) or oldest (ASC) entry in the database.""" await cursor.execute( - "SELECT timestamp FROM yupdates WHERE path = ? " f"ORDER BY timestamp {direction} LIMIT 1", + "SELECT timestamp FROM yupdates WHERE path = ? " + f"ORDER BY timestamp {direction} LIMIT 1", (self.path,), ) row = await cursor.fetchone() - return (time.time() - row[0]) if row else 0 \ No newline at end of file + return (time.time() - row[0]) if row else 0