#299 rpmautospec.specfile_uses_rpmautospec() cache is not invalidated on spec change
Closed: Fixed 9 months ago by nphilipp. Opened a year ago by churchyard.

>>> import pathlib, rpmautospec
>>> spec = pathlib.Path('xxx.spec')
>>> rpmautospec.specfile_uses_rpmautospec(spec)
False
>>> spec.write_text(spec.read_text().replace('1%{?dist}', '%autorelease'))
12345
>>> rpmautospec.specfile_uses_rpmautospec(spec)
False

Upon a new interpreter:

>>> import pathlib, rpmautospec
>>> spec = pathlib.Path('linkchecker.spec')
>>> rpmautospec.specfile_uses_rpmautospec(spec)
True

I believe the check_specfile_features() function should not be lru_cached. If the cache is needed, it should use the path+mtime+filesize triplet as a key.

Pseudocode:

@lru_cache(maxsize=None)
def _check_specfile_features_mtime_size(specpath, mtime, size):
    return ...

def check_specfile_features(specpath):
    stat = os.stat(specpath)
    return _check_specfile_features_mtime_size(specpath, stat.st_mtime, stat.st_size)

Good catch, thanks Miro!

One thing about the pseudocode portion, this looks like it would leak memory (if only little), keeping around stale results for the same spec file when its contents have changed. So we probably need to handle the cache more explicitly, whether or not we can do this using the functool decorators, no idea right now.

Metadata Update from @nphilipp:
- Issue tagged with: Bug, Changelog Functionality, Needs Deployment, Release Bumping Functionality

a year ago

Setting maxsize to a specific value will make sure the cache is limited and does not consume memory without limits (e.g. for a daemon service that uses this function). I suppose keeping just the latest 1024 results is a sensible default.

Login to comment on this ticket.

Metadata
Related Pull Requests
  • #305 Merged 9 months ago