least
This commit is contained in:
parent
b3b6361429
commit
71e14c8e63
3 changed files with 18 additions and 3 deletions
|
@ -18,7 +18,7 @@ from lbry.db.sync import (
|
||||||
condition_spent_claims, condition_spent_supports,
|
condition_spent_claims, condition_spent_supports,
|
||||||
select_missing_supports, process_claim_changes
|
select_missing_supports, process_claim_changes
|
||||||
)
|
)
|
||||||
from lbry.db.utils import greatest
|
from lbry.db.utils import least
|
||||||
from lbry.schema.url import normalize_name
|
from lbry.schema.url import normalize_name
|
||||||
|
|
||||||
from .lbrycrd import Lbrycrd
|
from .lbrycrd import Lbrycrd
|
||||||
|
@ -369,7 +369,7 @@ def process_metadata(starting_height: int, ending_height: int, initial_sync: boo
|
||||||
[(Claim.c.claim_hash == takeover['claim_hash'], takeover['height'])],
|
[(Claim.c.claim_hash == takeover['claim_hash'], takeover['height'])],
|
||||||
else_=None
|
else_=None
|
||||||
),
|
),
|
||||||
activation_height=greatest(Claim.c.activation_height, takeover['height']),
|
activation_height=least(Claim.c.activation_height, takeover['height']),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
p.ctx.execute(update_claims)
|
p.ctx.execute(update_claims)
|
||||||
|
|
|
@ -28,6 +28,21 @@ def sqlite_greatest(element, compiler, **kw):
|
||||||
return "max(%s)" % compiler.process(element.clauses, **kw)
|
return "max(%s)" % compiler.process(element.clauses, **kw)
|
||||||
|
|
||||||
|
|
||||||
|
class least(FunctionElement): # pylint: disable=invalid-name
|
||||||
|
type = Numeric()
|
||||||
|
name = 'least'
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(least)
|
||||||
|
def default_least(element, compiler, **kw):
|
||||||
|
return "least(%s)" % compiler.process(element.clauses, **kw)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(least, 'sqlite')
|
||||||
|
def sqlite_least(element, compiler, **kw):
|
||||||
|
return "min(%s)" % compiler.process(element.clauses, **kw)
|
||||||
|
|
||||||
|
|
||||||
def chunk(rows, step):
|
def chunk(rows, step):
|
||||||
it, total = iter(rows), len(rows)
|
it, total = iter(rows), len(rows)
|
||||||
for _ in range(0, total, step):
|
for _ in range(0, total, step):
|
||||||
|
|
|
@ -933,7 +933,7 @@ class TestClaimtrieSync(SyncingBlockchainTestCase):
|
||||||
])
|
])
|
||||||
await self.state(
|
await self.state(
|
||||||
controlling=('Claim C', '3.0', '3.0', 115),
|
controlling=('Claim C', '3.0', '3.0', 115),
|
||||||
active=[('Claim A', '1.0', '1.0', 115)],
|
active=[('Claim A', '1.0', '1.0', 113)],
|
||||||
accepted=[]
|
accepted=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue