2020-07-11 15:54:08 +00:00
|
|
|
import logging
|
2021-03-20 12:42:54 +00:00
|
|
|
from src.database import db
|
2020-07-11 15:54:08 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("rcgcdb.queue_handler")
|
|
|
|
|
2020-07-28 12:39:32 +00:00
|
|
|
|
|
|
|
class UpdateDB:
|
2020-07-11 15:54:08 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.updated = []
|
|
|
|
|
2020-08-02 21:40:30 +00:00
|
|
|
def add(self, wiki, rc_id, feeds=None):
|
2020-08-02 17:27:42 +00:00
|
|
|
self.updated.append((wiki, rc_id, feeds))
|
2020-07-11 15:54:08 +00:00
|
|
|
|
|
|
|
def clear_list(self):
|
|
|
|
self.updated.clear()
|
|
|
|
|
2021-03-18 16:00:01 +00:00
|
|
|
async def update_db(self):
|
2021-03-20 12:42:54 +00:00
|
|
|
async with db.pool().acquire() as connection:
|
|
|
|
async with connection.transaction():
|
|
|
|
for update in self.updated:
|
|
|
|
if update[2] is None:
|
|
|
|
sql = "UPDATE rcgcdw SET rcid = $2 WHERE wiki = $1 AND ( rcid != -1 OR rcid IS NULL )"
|
|
|
|
else:
|
|
|
|
sql = "UPDATE rcgcdw SET postid = $2 WHERE wiki = $1 AND ( postid != '-1' OR postid IS NULL )"
|
|
|
|
await connection.execute(sql, update[0], update[1])
|
|
|
|
self.clear_list()
|
2020-07-18 12:12:00 +00:00
|
|
|
|
|
|
|
|
2020-07-21 12:15:40 +00:00
|
|
|
DBHandler = UpdateDB()
|