Merge pull request #1313 from lnbits/gertytweak

Fix/gerty mempool caching timestamp bug (again)
This commit is contained in:
Arc 2023-01-05 22:33:41 +00:00 committed by GitHub
commit 4ea967f899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 4 deletions

View File

@ -117,19 +117,19 @@ async def get_mempool_info(endPoint: str, gerty) -> dict:
mempool_id,
json.dumps(response.json()),
endPoint,
db.timestamp_now,
time.time(),
gerty.mempool_endpoint,
),
)
return response.json()
if int(time.time()) - row.time > 20:
if float(time.time()) - row.time > 20:
async with httpx.AsyncClient() as client:
response = await client.get(gerty.mempool_endpoint + url)
await db.execute(
"UPDATE gerty.mempool SET data = ?, time = ? WHERE endpoint = ? AND mempool_endpoint = ?",
(
json.dumps(response.json()),
db.timestamp_now,
time.time(),
endPoint,
gerty.mempool_endpoint,
),

View File

@ -1,3 +1,6 @@
import time
async def m001_initial(db):
"""
Initial Gertys table.
@ -57,3 +60,46 @@ async def m005_add_gerty_model_col(db):
support for Gerty model col
"""
await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT;")
async def m006_add_gerty_model_col(db):
"""
Add UUID ID's to links and migrates existing data
"""
await db.execute("ALTER TABLE gerty.mempool RENAME TO mempool_old")
await db.execute(
f"""
CREATE TABLE gerty.mempool (
id TEXT PRIMARY KEY,
mempool_endpoint TEXT NOT NULL,
endpoint TEXT NOT NULL,
data TEXT NOT NULL,
time FLOAT
);
"""
)
for row in [
list(row) for row in await db.fetchall("SELECT * FROM gerty.mempool_old")
]:
await db.execute(
"""
INSERT INTO gerty.mempool (
id,
mempool_endpoint,
endpoint,
data,
time
)
VALUES (?, ?, ?, ?, ?)
""",
(
row[0],
row[1],
row[2],
row[3],
time.time(),
),
)
await db.execute("DROP TABLE gerty.mempool_old")

View File

@ -6,7 +6,7 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
v-if="fun_exchange_market_rate || fun_satoshi_quotes"
>
<q-card
v-if="fun_exchange_market_rate"
v-if="fun_exchange_market_rate[0]"
unelevated
class="q-pa-sm"
style="background: none !important"