Fixed a memory leak in the app when audio and video albums are updated

This commit is contained in:
Manuel Cortez 2018-12-20 08:33:16 -06:00
parent 48e3e39514
commit 30ecfd4370

View File

@ -221,8 +221,8 @@ class Controller(object):
def update_all_buffers(self): def update_all_buffers(self):
log.debug("Updating buffers...") log.debug("Updating buffers...")
self.get_audio_albums() self.get_audio_albums(create_buffers=False)
self.get_video_albums() self.get_video_albums(create_buffers=False)
for i in self.buffers: for i in self.buffers:
if hasattr(i, "get_items"): if hasattr(i, "get_items"):
i.get_items() i.get_items()
@ -482,53 +482,41 @@ class Controller(object):
i.reads = [] i.reads = []
time.sleep(1) time.sleep(1)
def get_audio_albums(self, user_id=None): def get_audio_albums(self, user_id=None, create_buffers=True):
try: log.debug("Create audio albums...")
log.debug("Create audio albums...") if self.session.settings["vk"]["use_alternative_tokens"]:
if self.session.settings["vk"]["use_alternative_tokens"]: albums = self.session.vk.client_audio.get_albums(owner_id=user_id)
albums = self.session.vk.client_audio.get_albums(owner_id=user_id) else:
else: albums = self.session.vk.client.audio.getPlaylists(owner_id=user_id)
albums = self.session.vk.client.audio.getPlaylists(owner_id=user_id) albums = albums["items"]
albums = albums["items"]
except SyntaxError:#VkApiError as ex:
if ex.code == 6:
log.exception("Something went wrong when getting albums. Waiting a second to retry")
time.sleep(2)
return self.get_audio_albums(user_id=user_id)
elif ex.code == 10:
return
self.session.audio_albums = albums self.session.audio_albums = albums
for i in albums: if create_buffers:
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=user_id, album_id=i["id"]) for i in albums:
buffer.can_get_items = False buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=user_id, album_id=i["id"])
# Translators: {0} Will be replaced with an audio album's title. buffer.can_get_items = False
name_ = _(u"Album: {0}").format(i["title"],) # Translators: {0} Will be replaced with an audio album's title.
self.buffers.append(buffer) name_ = _(u"Album: {0}").format(i["title"],)
self.window.insert_buffer(buffer.tab, name_, self.window.search("albums")) self.buffers.append(buffer)
buffer.get_items() self.window.insert_buffer(buffer.tab, name_, self.window.search("albums"))
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK. buffer.get_items()
time.sleep(0.3) # inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
time.sleep(0.3)
def get_video_albums(self, user_id=None): def get_video_albums(self, user_id=None, create_buffers=True):
try: log.debug("Create video albums...")
log.debug("Create video albums...") albums = self.session.vk.client.video.getAlbums(owner_id=user_id)
albums = self.session.vk.client.video.getAlbums(owner_id=user_id)
except VkApiError as ex:
if ex.code == 6:
log.exception("Something went wrong when getting albums. Waiting a second to retry")
time.sleep(2)
return self.get_audio_albums(user_id=user_id)
self.session.video_albums = albums["items"] self.session.video_albums = albums["items"]
for i in albums["items"]: if create_buffers:
buffer = buffers.videoAlbum(parent=self.window.tb, name="{0}_video_album".format(i["id"],), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=user_id, album_id=i["id"]) for i in albums["items"]:
buffer.can_get_items = False buffer = buffers.videoAlbum(parent=self.window.tb, name="{0}_video_album".format(i["id"],), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=user_id, album_id=i["id"])
# Translators: {0} Will be replaced with a video album's title. buffer.can_get_items = False
name_ = _(u"Album: {0}").format(i["title"],) # Translators: {0} Will be replaced with a video album's title.
self.buffers.append(buffer) name_ = _(u"Album: {0}").format(i["title"],)
self.window.insert_buffer(buffer.tab, name_, self.window.search("video_albums")) self.buffers.append(buffer)
buffer.get_items() self.window.insert_buffer(buffer.tab, name_, self.window.search("video_albums"))
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK. buffer.get_items()
time.sleep(0.3) # inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
time.sleep(0.3)
def create_audio_album(self, *args, **kwargs): def create_audio_album(self, *args, **kwargs):
d = creation.audio_album() d = creation.audio_album()