use equality to filter token prefixes

otherwise, index isn't used

note: this means changing the token prefix size requires revoking all tokens,
where before only _increasing_ the token prefix size required doing that.
This commit is contained in:
Min RK
2022-05-25 15:53:48 +02:00
parent 9649a57e34
commit e229c63e11

View File

@@ -528,9 +528,7 @@ class Hashed(Expiring):
prefix = token[: cls.prefix_length]
# since we can't filter on hashed values, filter on prefix
# so we aren't comparing with all tokens
prefix_match = db.query(cls).filter(
bindparam('prefix', prefix).startswith(cls.prefix)
)
prefix_match = db.query(cls).filter_by(prefix=prefix)
prefix_match = prefix_match.filter(
or_(cls.expires_at == None, cls.expires_at >= cls.now())
)