Skip to content

Commit abd2ae9

Browse files
committed
Fix chart to fetch all data for timeframe, not limited
1 parent 6b20b14 commit abd2ae9

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

chart_service.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,7 @@ async def get_chart_bytes(
215215
) -> Optional[bytes]:
216216
"""Get price history from DB and generate chart."""
217217
max_points = 800 if hours <= 24 else 1200 if hours <= 168 else 1500
218-
limit = max_points * 2
219-
history = await db.get_price_history(
220-
crypto, hours=hours, limit=limit, descending=True
221-
)
218+
history = await db.get_price_history(crypto, hours=hours, descending=True)
222219

223220
if not history or len(history) < 2:
224221
return None

database.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,27 @@ async def get_price_history(
253253
query = query.replace("ORDER BY timestamp ASC", f"ORDER BY timestamp {order}")
254254

255255
async with self.pool.acquire() as conn:
256-
rows = await conn.fetch(query, crypto_name.upper(), cutoff, limit)
256+
if limit is None:
257+
rows = await conn.fetch(query, crypto_name.upper(), cutoff)
258+
else:
259+
rows = await conn.fetch(query, crypto_name.upper(), cutoff, limit)
257260

258261
if not rows and bucket_type != "raw":
259-
query = f"""
260-
SELECT timestamp, price FROM prices
261-
WHERE crypto_name = $1 AND timestamp > $2
262-
ORDER BY timestamp {order}
263-
LIMIT $3
264-
"""
265-
rows = await conn.fetch(query, crypto_name.upper(), cutoff, limit)
262+
if limit is None:
263+
query = f"""
264+
SELECT timestamp, price FROM prices
265+
WHERE crypto_name = $1 AND timestamp > $2
266+
ORDER BY timestamp {order}
267+
"""
268+
rows = await conn.fetch(query, crypto_name.upper(), cutoff)
269+
else:
270+
query = f"""
271+
SELECT timestamp, price FROM prices
272+
WHERE crypto_name = $1 AND timestamp > $2
273+
ORDER BY timestamp {order}
274+
LIMIT $3
275+
"""
276+
rows = await conn.fetch(query, crypto_name.upper(), cutoff, limit)
266277

267278
return [(r["timestamp"], float(r["price"])) for r in rows]
268279

0 commit comments

Comments
 (0)