Try exact match first for update state (#69335)

- Exact matches are much cheaper than creating an AwesomeVersion
  and calling the __gt__ method, and since most of the time the
  result is expected to be off, we want to optimize for this case
This commit is contained in:
J. Nick Koston 2022-04-05 03:51:25 -10:00 committed by GitHub
parent 2cf3057ff1
commit 1a9420dda0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -327,13 +327,15 @@ class UpdateEntity(RestoreEntity):
if latest_version == self.__skipped_version:
return STATE_OFF
if latest_version == installed_version:
return STATE_OFF
try:
newer = AwesomeVersion(latest_version) > installed_version
return STATE_ON if newer else STATE_OFF
except AwesomeVersionCompareException:
# Can't compare versions, fallback to exact match
return STATE_OFF if latest_version == installed_version else STATE_ON
# Can't compare versions, already tried exact match
return STATE_ON
@final
@property