Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/cache.py
Show First 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | async def get(self, swhid: SWHID) -> Optional[List[SWHID]]: | ||||
return None | return None | ||||
history = [] | history = [] | ||||
for parent in cache: | for parent in cache: | ||||
parent = parent[0] | parent = parent[0] | ||||
try: | try: | ||||
history.append(parse_swhid(parent)) | history.append(parse_swhid(parent)) | ||||
except ValidationError: | except ValidationError: | ||||
logging.warning(f"Cannot parse object from history cache: {parent}") | logging.warning("Cannot parse object from history cache: %s", parent) | ||||
return history | return history | ||||
async def set(self, history: str) -> None: | async def set(self, history: str) -> None: | ||||
history = history.strip() | history = history.strip() | ||||
edges = [edge.split(" ") for edge in history.split("\n")] | edges = [edge.split(" ") for edge in history.split("\n")] | ||||
await self.conn.executemany( | await self.conn.executemany( | ||||
"insert or ignore into history_graph values (?, ?)", edges | "insert or ignore into history_graph values (?, ?)", edges | ||||
) | ) | ||||
Show All 39 Lines | class LRU(OrderedDict): | ||||
while self.used_ram > self.max_ram and self: | while self.used_ram > self.max_ram and self: | ||||
oldest = next(iter(self)) | oldest = next(iter(self)) | ||||
self.used_ram -= self.sizeof(oldest) | self.used_ram -= self.sizeof(oldest) | ||||
del self[oldest] | del self[oldest] | ||||
def __init__(self, conf: Dict[str, Any]): | def __init__(self, conf: Dict[str, Any]): | ||||
m = re.match(r"(\d+)\s*(.+)\s*", conf["maxram"]) | m = re.match(r"(\d+)\s*(.+)\s*", conf["maxram"]) | ||||
if not m: | if not m: | ||||
logging.error(f"Cannot parse direntry maxram config: {conf['maxram']}") | logging.error("Cannot parse direntry maxram config: %s", conf["maxram"]) | ||||
sys.exit(1) | sys.exit(1) | ||||
num = float(m.group(1)) | num = float(m.group(1)) | ||||
unit = m.group(2).upper() | unit = m.group(2).upper() | ||||
if unit == "%": | if unit == "%": | ||||
max_ram = int(num * virtual_memory().available / 100) | max_ram = int(num * virtual_memory().available / 100) | ||||
else: | else: | ||||
Show All 15 Lines |