From 35d550d229b219f5a02cb9194c3bd24329f975ed Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 16 May 2019 00:31:40 +0200 Subject: [PATCH] Use memoization get _*_path() functions This shouldn't make a big difference in the CLI/extension usage, but might improve the performances of long-running instances, or people misusing the API. --- libmat2/exiftool.py | 2 ++ libmat2/video.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libmat2/exiftool.py b/libmat2/exiftool.py index d18b1fb..2e83f13 100644 --- a/libmat2/exiftool.py +++ b/libmat2/exiftool.py @@ -1,3 +1,4 @@ +import functools import json import logging import os @@ -56,6 +57,7 @@ class ExiftoolParser(abstract.AbstractParser): return False return True +@functools.lru_cache() def _get_exiftool_path() -> str: # pragma: no cover possible_pathes = { '/usr/bin/exiftool', # debian/fedora diff --git a/libmat2/video.py b/libmat2/video.py index 0060f78..1492ba1 100644 --- a/libmat2/video.py +++ b/libmat2/video.py @@ -1,3 +1,4 @@ +import functools import os import logging @@ -130,6 +131,7 @@ class MP4Parser(AbstractFFmpegParser): } +@functools.lru_cache() def _get_ffmpeg_path() -> str: # pragma: no cover ffmpeg_path = '/usr/bin/ffmpeg' if os.path.isfile(ffmpeg_path):