forked from LBRYCommunity/lbry-sdk
addeed greatest sql function that supports postgres and sqlite
This commit is contained in:
parent
54a0bf9290
commit
d8fb31aedd
4 changed files with 28 additions and 3 deletions
|
@ -18,6 +18,7 @@ from lbry.db.sync import (
|
|||
condition_spent_claims, condition_spent_supports,
|
||||
select_missing_supports, process_claim_changes
|
||||
)
|
||||
from lbry.db.utils import greatest
|
||||
from lbry.schema.url import normalize_name
|
||||
|
||||
from .lbrycrd import Lbrycrd
|
||||
|
@ -368,7 +369,7 @@ def process_metadata(starting_height: int, ending_height: int, initial_sync: boo
|
|||
[(Claim.c.claim_hash == takeover['claim_hash'], takeover['height'])],
|
||||
else_=None
|
||||
),
|
||||
activation_height=func.min(Claim.c.activation_height, takeover['height']),
|
||||
activation_height=greatest(Claim.c.activation_height, takeover['height']),
|
||||
)
|
||||
)
|
||||
p.ctx.execute(update_claims)
|
||||
|
|
|
@ -100,6 +100,11 @@ class Advanced(Basic):
|
|||
if event == "save" and d['step'] == d['total']:
|
||||
bar.close()
|
||||
|
||||
def update_other_bars(self, e, d):
|
||||
bar = self.get_or_create_bar(e, e, d['unit'], d['total'], leave=True)
|
||||
diff = d['step']-bar.last_print_n
|
||||
bar.update(diff)
|
||||
|
||||
def on_sync_progress(self, event):
|
||||
e, d = event['event'], event.get('data', {})
|
||||
if e.endswith("start"):
|
||||
|
@ -110,3 +115,5 @@ class Advanced(Basic):
|
|||
self.update_sync_block_bars("read", d)
|
||||
elif e.endswith("block.save"):
|
||||
self.update_sync_block_bars("save", d)
|
||||
else:
|
||||
self.update_other_bars(e, d)
|
||||
|
|
|
@ -463,7 +463,7 @@ class BulkLoader:
|
|||
if claim.is_signed:
|
||||
claim_record['channel_hash'] = claim.signing_channel_hash
|
||||
claim_record['signature'] = txo.get_encoded_signature()
|
||||
claim_record['signature_digest'] = txo.get_signature_digest(None)
|
||||
claim_record['signature_digest'] = txo.get_signature_digest(self.ledger)
|
||||
|
||||
tags = [
|
||||
{'claim_hash': claim_hash, 'tag': tag} for tag in clean_tags(claim.message.tags)
|
||||
|
|
|
@ -2,7 +2,9 @@ from itertools import islice
|
|||
from typing import List, Union
|
||||
|
||||
from sqlalchemy import text, and_
|
||||
from sqlalchemy.sql.expression import Select
|
||||
from sqlalchemy.sql.expression import Select, FunctionElement
|
||||
from sqlalchemy.types import Numeric
|
||||
from sqlalchemy.ext.compiler import compiles
|
||||
try:
|
||||
from sqlalchemy.dialects.postgresql import insert as pg_insert # pylint: disable=unused-import
|
||||
except ImportError:
|
||||
|
@ -11,6 +13,21 @@ except ImportError:
|
|||
from .tables import AccountAddress
|
||||
|
||||
|
||||
class greatest(FunctionElement):
|
||||
type = Numeric()
|
||||
name = 'greatest'
|
||||
|
||||
|
||||
@compiles(greatest)
|
||||
def default_greatest(element, compiler, **kw):
|
||||
return "greatest(%s)" % compiler.process(element.clauses, **kw)
|
||||
|
||||
|
||||
@compiles(greatest, 'sqlite')
|
||||
def sqlite_greatest(element, compiler, **kw):
|
||||
return "max(%s)" % compiler.process(element.clauses, **kw)
|
||||
|
||||
|
||||
def chunk(rows, step):
|
||||
it, total = iter(rows), len(rows)
|
||||
for _ in range(0, total, step):
|
||||
|
|
Loading…
Reference in a new issue