Skip to content

Commit

Permalink
tool/hoardy_web/*: make_FileSource: call stat less
Browse files Browse the repository at this point in the history
  • Loading branch information
oxij committed Dec 5, 2024
1 parent d717f89 commit 973786c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion tool/hoardy_web/mitmproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import io as _io
import os as _os
import struct as _struct
import typing as _t

Expand Down Expand Up @@ -128,4 +129,5 @@ def rrexprs_mitmproxy_load_fileobj(fobj : _io.BufferedReader, source : DeferredS

def rrexprs_mitmproxy_loadf(path : str | bytes) -> _t.Iterator[ReqresExpr[StreamElementSource[FileSource]]]:
with open(path, "rb") as f:
yield from rrexprs_mitmproxy_load_fileobj(f, make_FileSource(path, f))
in_stat = _os.fstat(f.fileno())
yield from rrexprs_mitmproxy_load_fileobj(f, make_FileSource(path, in_stat))
4 changes: 1 addition & 3 deletions tool/hoardy_web/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ def replaces(self, other : DeferredSource) -> bool:
return False
return True

def make_FileSource(path : str | bytes, fobj : _io.BufferedReader, in_stat : _os.stat_result | None = None) -> FileSource:
if in_stat is None:
in_stat = _os.fstat(fobj.fileno())
def make_FileSource(path : str | bytes, in_stat : _os.stat_result) -> FileSource:
return FileSource(path, in_stat.st_mtime_ns, in_stat.st_dev, in_stat.st_ino)

DeferredSourceType = _t.TypeVar("DeferredSourceType", bound=DeferredSource)
Expand Down
9 changes: 6 additions & 3 deletions tool/hoardy_web/wrr.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,15 +699,18 @@ def rrexprs_wrr_some_load(fobj : _io.BufferedReader, source : DeferredSourceType

def rrexpr_wrr_loadf(path : str | bytes, in_stat : _os.stat_result | None = None) -> ReqresExpr[FileSource]:
with open(path, "rb") as f:
return rrexpr_wrr_load(f, make_FileSource(path, f, in_stat))
in_stat = _os.fstat(f.fileno())
return rrexpr_wrr_load(f, make_FileSource(path, in_stat))

def rrexprs_wrr_bundle_loadf(path : str | bytes, in_stat : _os.stat_result | None = None) -> _t.Iterator[ReqresExpr[StreamElementSource[FileSource]]]:
with open(path, "rb") as f:
yield from rrexprs_wrr_bundle_load(f, make_FileSource(path, f, in_stat))
in_stat = _os.fstat(f.fileno())
yield from rrexprs_wrr_bundle_load(f, make_FileSource(path, in_stat))

def rrexprs_wrr_some_loadf(path : str | bytes, in_stat : _os.stat_result | None = None) -> _t.Iterator[ReqresExpr[FileSource | StreamElementSource[FileSource]]]:
with open(path, "rb") as f:
yield from rrexprs_wrr_some_load(f, make_FileSource(path, f, in_stat))
in_stat = _os.fstat(f.fileno())
yield from rrexprs_wrr_some_load(f, make_FileSource(path, in_stat))

def trivial_Reqres(url : ParsedURL,
content_type : str = "text/html",
Expand Down

0 comments on commit 973786c

Please sign in to comment.