Finish precaching, background updates, and placeholder items#98
Conversation
… background updating
…uild the group properly on add
… background updating
| props=properties, | ||
| ) | ||
| # Ensure we precache next page for faster access | ||
| cache.cache_expiry(file["file"], widget_id, background=True) |
There was a problem hiding this comment.
Here's the magic of pre-caching a "Next Page" item.
| props=properties, | ||
| ) | ||
| # Ensure we precache next page for faster access | ||
| cache.cache_expiry(file["file"], widget_id) |
There was a problem hiding this comment.
Here's the magic where we pre-cache the next page.
There was a problem hiding this comment.
I think this means a precached next page is going to cause an unneeded widget redraw. Pass some flag in teh queue file to say not to refresh the widget if its a precache?
| return titles if titles else True, path_label, content | ||
|
|
||
| utils.log("Loading items from {}".format(path), "debug") | ||
| files, hash = refresh.get_files_list(path, path_label, widget_id) |
There was a problem hiding this comment.
Passing path_label through this allows us to properly label the placeholder tiles.
| ) # Just in queued path's widget defintion has changed and it didn't update this path | ||
| unrefreshed_widgets = unrefreshed_widgets.union( | ||
| effected_widgets | ||
| affected_widgets |
| hash, widget_ids = queue.pop(0) | ||
| utils.log("Dequeued cache update: {}".format(hash[:5]), "notice") | ||
|
|
||
| affected_widgets = cache.cache_and_update( |
There was a problem hiding this comment.
This bit right here makes sure to cache any queued paths any time they show up.
| def get_files_list(path, widget_id=None): | ||
| hash = utils.path2hash(path) | ||
| _, files, _ = utils.cache_expiry(hash, widget_id) | ||
| def get_files_list(path, label=None, widget_id=None, background=True): |
There was a problem hiding this comment.
We always do caching in the background, except in the case of exploding/cloning.
There was a problem hiding this comment.
I was thinking next page should not be done in the background but I guess if its always precached then this is no longer a problem
| # Should only happen now when background is False | ||
| utils.log("Blocking cache path read: {}".format(hash[:5]), "info") | ||
| files, changed = utils.cache_files(path, widget_id) | ||
| files, changed = cache.cache_files(path, widget_id) |
There was a problem hiding this comment.
Create a cache for the path if there isn't one already.
| else: | ||
| utils.log("Error processing {}".format(hash), "error") | ||
| return None, hash | ||
| error_tile = utils.make_holding_path( |
There was a problem hiding this comment.
Create an "error state" tile if the JSON response in the existing cache file is invalid in some way.
| cache_path = os.path.join(_addon_data, "{}.cache".format(hash)) | ||
| if os.path.exists(cache_path): | ||
| os.remove(cache_path) | ||
| utils.log("Invalid cache file removed for {}".format(hash)) |
There was a problem hiding this comment.
If that is the case, we'll go ahead and remove that cache file now, so that we don't hold an invalid cache.
|
|
||
| if not files: | ||
| utils.log("No items found for {}".format(hash)) | ||
| empty_tile = utils.make_holding_path( |
There was a problem hiding this comment.
If the cache is valid, but there are no files to return, then we make an "empty path" tile instead.
| for file in files: | ||
| new_file = {k: v for k, v in file.items() if v is not None} | ||
|
|
||
| def queue_widget_update(widget_id): |
There was a problem hiding this comment.
It didn't seem that this method was actually used anywhere, so I just got rid of it again.
There was a problem hiding this comment.
yes. original way I tried to do queues. not used anymore but useful to know there is another way to communicate with the service process
There was a problem hiding this comment.
@djay I've commented up the PR a bit, so you can check and see if you think my changes are reasonable 👍
| msgstr "No content found for {}" | ||
|
|
||
| #: /resources/lib/refresh.py:95 | ||
| msgctxt "#30141" |
There was a problem hiding this comment.
I "viewed" all of the other .po files, but these are the new translations I added.
|
The other thing that sticks out to me a lot in this code is that there are a lot of leftover commented bits and "todos", but those should probably be tackled in a further "refactor" PR focused on performance and flexibility of these caching processes. |
a905d44 to
9542859
Compare
…de_errors_bug_fix_edition
…de_errors_bug_fix_edition
…tion Djay/hande errors bug fix edition
|
I should probably go through the TODOs. Often they get fixed later somewhere else I forget I had a TODO for it. Some other TODOs might be better moved to github feature requests. Like periodic caching cleaning to reduce space. I think most of the rest of the TODOs are around estimating how long to cache a path, or the likelyhood of a path needing updating after playback. Not sure if these are enabled in the latest code? |
So, refreshing after playback is included in this PR, but it should also be in I'd like to go ahead and merge this in soon, and start looking at some other potential refactoring and performance increases for a future major update, which will likely include some of those caching mechanisms. Also, for what it's worth, this PR moves most all of the caching stuff to |
This PR builds on code from #76, and largely covers precaching of paths which will be displayed in the future, like "Next Page" paths and others in the same Cycling Widget. It also adds three "placeholder" items that can appear during widget load:
This PR also ensures that we don't save an invalid cache for the latter case, and adds some notifications about various background processes, like exploding paths and updating widgets in the background.