Make the number of lines and messages kept in memory configurable

and lower (a lot) the number of lines kept in the info_win buffers
This lower the memory usage.
This commit is contained in:
Florent Le Coz 2011-02-14 14:54:26 +01:00
parent 3e550f4ae7
commit 4b31e5acf1
5 changed files with 18 additions and 11 deletions

View file

@ -141,6 +141,12 @@ send_os_info = true
# Set to false if you don't want people to know that information
send_time = true
# Configure the number of maximum lines and messages (for each tab) that
# can be kept in memory. If poezio consumes too much memory, lower these
# values
max_messages_in_memory = 2048
max_lines_in_memory = 2048
[var]
# You should not edit this section, it is just used by poezio
# to save various data across restarts

View file

@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Poezio. If not, see <http://www.gnu.org/licenses/>.
from text_buffer import TextBuffer, MESSAGE_NB_LIMIT
from text_buffer import TextBuffer
from datetime import datetime
from random import randrange
from config import config
@ -29,8 +29,8 @@ import logging
log = logging.getLogger(__name__)
class Room(TextBuffer):
def __init__(self, name, nick):
TextBuffer.__init__(self)
def __init__(self, name, nick, messages_nb_limit=config.get('max_messages_in_memory', 2048)):
TextBuffer.__init__(self, messages_nb_limit)
self.name = name
self.own_nick = nick
self.color_state = theme.COLOR_TAB_NORMAL # color used in RoomInfo
@ -115,7 +115,7 @@ class Room(TextBuffer):
time = time if time is not None else datetime.now()
nick_color = nick_color or user.color if user else None
message = Message(txt, time, nickname, nick_color, color, colorized, user=user)
while len(self.messages) > MESSAGE_NB_LIMIT:
while len(self.messages) > self.messages_nb_limit:
self.messages.pop(0)
self.messages.append(message)
for window in self.windows: # make the associated windows

View file

@ -261,7 +261,7 @@ class ChatTab(Tab):
class TabWithInfoWin(Tab):
def __init__(self):
self.info_win = windows.TextWin()
self.info_win = windows.TextWin(20)
self.core.information_buffer.add_window(self.info_win)
def __del__(self):

View file

@ -24,15 +24,15 @@ log = logging.getLogger(__name__)
from message import Message
from datetime import datetime
import theme
MESSAGE_NB_LIMIT = 8192
from config import config
class TextBuffer(object):
"""
This class just keep trace of messages, in a list with various
informations and attributes.
"""
def __init__(self):
def __init__(self, messages_nb_limit=config.get('max_messages_in_memory', 2048)):
self.messages_nb_limit = messages_nb_limit
self.messages = [] # Message objects
self.windows = [] # we keep track of one or more windows
# so we can pass the new messages to them, as they are added, so
@ -47,7 +47,7 @@ class TextBuffer(object):
time = time or datetime.now()
msg = Message(txt, time, nickname, nick_color, color, colorized)
self.messages.append(msg)
while len(self.messages) > MESSAGE_NB_LIMIT:
while len(self.messages) > self.messages_nb_limit:
self.messages.pop(0)
for window in self.windows: # make the associated windows
# build the lines from the new message

View file

@ -432,8 +432,9 @@ class MucInfoWin(InfoWin):
self.addstr(txt, curses.color_pair(theme.COLOR_INFORMATION_BAR))
class TextWin(Win):
def __init__(self):
def __init__(self, lines_nb_limit=config.get('max_lines_in_memory', 2048)):
Win.__init__(self)
self.lines_nb_limit = lines_nb_limit
self.pos = 0
self.built_lines = [] # Each new message is built and kept here.
# on resize, we rebuild all the messages
@ -525,7 +526,7 @@ class TextWin(Win):
if txt.startswith('\n'):
txt = txt[1:]
first = False
while len(self.built_lines) > LINES_NB_LIMIT:
while len(self.built_lines) > self.lines_nb_limit:
self.built_lines.pop(0)
return nb