~liberachat/beryllia

40693269e2bb6942f7df8ae7bd6560a4445cd2c3 — jesopo a month ago 9eb98b8
fix a number of kcheck-related SELECTs that were not ordering output
M beryllia/__init__.py => beryllia/__init__.py +1 -1
@@ 258,7 258,7 @@ class Server(BaseServer):
            caller.oper, int(args[0])
        )
        outs: List[str] = []
        for kline_id in kline_ids:
        for kline_id, _ in kline_ids:
            outs += await self._ktag(kline_id, args[1], caller)
        if not outs:
            outs = ["found no recent k-lines from you"]

M beryllia/database/kline.py => beryllia/database/kline.py +21 -29
@@ 103,35 103,6 @@ class KLineTable(Table):
        async with self.pool.acquire() as conn:
            await conn.execute(query, kline_id)

    async def find_by_ts(
        self, ts: datetime, count: int, fudge: int = 1
    ) -> Collection[Tuple[int, datetime]]:

        query = """
            SELECT id, ts FROM kline
            WHERE ABS(
                EXTRACT(
                    EPOCH FROM (
                        DATE_TRUNC('minute', ts) - $1
                    )
                )
            ) / 60 <= $2
            LIMIT $3
        """
        async with self.pool.acquire() as conn:
            return await conn.fetch(query, ts, fudge, count)

    async def find_last_by_oper(self, oper: str, count: int) -> Sequence[int]:
        query = """
            SELECT id FROM kline
            WHERE oper = $1
            ORDER BY ts DESC
            LIMIT $2
        """
        async with self.pool.acquire() as conn:
            rows = await conn.fetch(query, oper, count)
        return [r[0] for r in rows]

    async def _find_klines(
        self, where: str, args: Sequence[Any], count: int
    ) -> Collection[Tuple[int, datetime]]:


@@ 140,6 111,7 @@ class KLineTable(Table):
            SELECT id, ts
            FROM kline
            {where}
            ORDER BY ts DESC
            LIMIT {count}
        """



@@ 148,6 120,26 @@ class KLineTable(Table):

        return rows

    async def find_last_by_oper(
        self, oper: str, count: int
    ) -> Collection[Tuple[int, datetime]]:
        return await self._find_klines("WHERE oper = $1", [oper], count)

    async def find_by_ts(
        self, ts: datetime, count: int, fudge: int = 1
    ) -> Collection[Tuple[int, datetime]]:

        where = """
            WHERE ABS(
                EXTRACT(
                    EPOCH FROM (
                        DATE_TRUNC('minute', ts) - $1
                    )
                )
            ) / 60 <= $2
        """
        return await self._find_klines(where, [ts, fudge], count)

    async def find_by_mask_glob(
        self, mask: str, count: int
    ) -> Collection[Tuple[int, datetime]]:

M beryllia/database/kline_kill.py => beryllia/database/kline_kill.py +1 -0
@@ 70,6 70,7 @@ class KLineKillTable(Table):
            INNER JOIN kline
            ON kline_kill.kline_id = kline.id
            {where}
            ORDER BY kline.ts DESC
            LIMIT {count}
        """


M beryllia/database/kline_tag.py => beryllia/database/kline_tag.py +2 -1
@@ 52,11 52,12 @@ class KLineTagTable(Table):
        self, tag: str, count: int
    ) -> Collection[Tuple[int, datetime]]:
        query = """
            SELECT DISTINCT(kline.id), kline.ts
            SELECT kline.id, kline.ts
                FROM kline_tag
            INNER JOIN kline
                ON kline_tag.kline_id = kline.id
            WHERE kline_tag.search_tag LIKE $1
            ORDER BY kline.ts DESC
            LIMIT $2
        """
        pattern = glob_to_sql(lex_glob_pattern(tag))