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,22 +482,15 @@ 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
if create_buffers:
for i in albums: for i in albums:
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"]) 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"])
buffer.can_get_items = False buffer.can_get_items = False
@ -509,16 +502,11 @@ class Controller(object):
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK. # inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
time.sleep(0.3) 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"]
if create_buffers:
for i in albums["items"]: for i in albums["items"]:
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"]) 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"])
buffer.can_get_items = False buffer.can_get_items = False