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

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

Upon a new interpreter:

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

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.


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

6 months 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.

Related Pull Requests
  • #305 Merged 3 months ago