mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 01:29:48 +00:00
console: improve flowlist performance (#5228)
Co-authored-by: BkPHcgQL3V <BkPHcgQL3V@gmx.com>
This commit is contained in:
parent
66dd158560
commit
31add1a7c0
@ -2,6 +2,8 @@
|
||||
|
||||
## Unreleased: mitmproxy next
|
||||
|
||||
* Console Performance Improvements
|
||||
([#3427](https://github.com/mitmproxy/mitmproxy/issues/3427), @BkPHcgQL3V)
|
||||
* Add flatpak support to the browser addon
|
||||
([#5200](https://github.com/mitmproxy/mitmproxy/issues/5200), @pauloromeira)
|
||||
* Add example addon to dump contents to files based on a filter expression
|
||||
|
@ -1,8 +1,11 @@
|
||||
import typing
|
||||
from functools import lru_cache
|
||||
|
||||
import urwid
|
||||
|
||||
import mitmproxy.tools.console.master
|
||||
from mitmproxy.tools.console import common
|
||||
from mitmproxy.tools.console import layoutwidget
|
||||
import mitmproxy.tools.console.master
|
||||
|
||||
|
||||
class FlowItem(urwid.WidgetWrap):
|
||||
@ -40,6 +43,7 @@ class FlowItem(urwid.WidgetWrap):
|
||||
|
||||
|
||||
class FlowListWalker(urwid.ListWalker):
|
||||
master: "mitmproxy.tools.console.master.ConsoleMaster"
|
||||
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
@ -47,13 +51,14 @@ class FlowListWalker(urwid.ListWalker):
|
||||
def positions(self, reverse=False):
|
||||
# The stub implementation of positions can go once this issue is resolved:
|
||||
# https://github.com/urwid/urwid/issues/294
|
||||
ret = range(self.master.commands.execute("view.properties.length"))
|
||||
ret = range(self.master.view.get_length())
|
||||
if reverse:
|
||||
return reversed(ret)
|
||||
return ret
|
||||
|
||||
def view_changed(self):
|
||||
self._modified()
|
||||
self._get.cache_clear()
|
||||
|
||||
def get_focus(self):
|
||||
if not self.master.view.focus.flow:
|
||||
@ -65,19 +70,17 @@ class FlowListWalker(urwid.ListWalker):
|
||||
if self.master.commands.execute("view.properties.inbounds %d" % index):
|
||||
self.master.view.focus.index = index
|
||||
|
||||
def get_next(self, pos):
|
||||
pos = pos + 1
|
||||
if not self.master.commands.execute("view.properties.inbounds %d" % pos):
|
||||
@lru_cache(maxsize=None)
|
||||
def _get(self, pos: int) -> typing.Tuple[typing.Optional[FlowItem], typing.Optional[int]]:
|
||||
if not self.master.view.inbounds(pos):
|
||||
return None, None
|
||||
f = FlowItem(self.master, self.master.view[pos])
|
||||
return f, pos
|
||||
return FlowItem(self.master, self.master.view[pos]), pos
|
||||
|
||||
def get_next(self, pos):
|
||||
return self._get(pos + 1)
|
||||
|
||||
def get_prev(self, pos):
|
||||
pos = pos - 1
|
||||
if not self.master.commands.execute("view.properties.inbounds %d" % pos):
|
||||
return None, None
|
||||
f = FlowItem(self.master, self.master.view[pos])
|
||||
return f, pos
|
||||
return self._get(pos - 1)
|
||||
|
||||
|
||||
class FlowListBox(urwid.ListBox, layoutwidget.LayoutWidget):
|
||||
|
Loading…
Reference in New Issue
Block a user