Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 10, 2024
1 parent 4d11ff0 commit 5fc1bd2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pycrdt_websocket/ystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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
return (time.time() - row[0]) if row else 0

0 comments on commit 5fc1bd2

Please sign in to comment.