MCPcopy Index your code
hub / github.com/AstrBotDevs/AstrBot / insert_platform_stats

Method insert_platform_stats

astrbot/core/db/sqlite.py:135–166  ·  view source on GitHub ↗

Insert a new platform statistic record.

(
        self,
        platform_id,
        platform_type,
        count=1,
        timestamp=None,
    )

Source from the content-addressed store, hash-verified

133 # ====
134
135 async def insert_platform_stats(
136 self,
137 platform_id,
138 platform_type,
139 count=1,
140 timestamp=None,
141 ) -> None:
142 """Insert a new platform statistic record."""
143 async with self.get_db() as session:
144 session: AsyncSession
145 async with session.begin():
146 if timestamp is None:
147 timestamp = datetime.now().replace(
148 minute=0,
149 second=0,
150 microsecond=0,
151 )
152 current_hour = timestamp
153 await session.execute(
154 text("""
155 INSERT INTO platform_stats (timestamp, platform_id, platform_type, count)
156 VALUES (:timestamp, :platform_id, :platform_type, :count)
157 ON CONFLICT(timestamp, platform_id, platform_type) DO UPDATE SET
158 count = platform_stats.count + EXCLUDED.count
159 """),
160 {
161 "timestamp": current_hour,
162 "platform_id": platform_id,
163 "platform_type": platform_type,
164 "count": count,
165 },
166 )
167
168 async def count_platform_stats(self) -> int:
169 """Count the number of platform statistics records."""

Callers

nothing calls this directly

Calls 3

nowMethod · 0.80
get_dbMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected