-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added method to clear model cache and force a model build (#583) #586
Conversation
Could you add a test for this? there are already a bunch for the paged controller |
Yeah, I'll do it in the next days or weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kakai248 sorry for the long delay, I'm not too familiar with this code and wanted to make sure I dedicated time to understand it.
I think the overall approach makes sense, but would like to see the test improved
(0 until modelCache.size).forEach { | ||
modelCache[it] = null | ||
} | ||
rebuildCallback() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that this method should call rebuildCallback()
- since the intention of the method is to clear
everything. If you want to also rebuild them this could be named more like forceRebuildAllModels
However, since requestForcedModelBuild
calls this clear method as well as requestModelBuild()
then requestModelBuild()
is basically being called twice which is unnecessary, so it seems fine to remove the building callback from clearModels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I removed the callback call.
@@ -236,6 +236,13 @@ class PagedListModelCacheTest { | |||
} | |||
} | |||
|
|||
@Test | |||
fun clear() { | |||
pagedListModelCache.clearModels() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaik this doesn't test that models are cleared, just that models are rebuilt. I think a good way to test the behavior is to check that all models are rebuilt - maybe by adding a counter in the modelBuilder
callback similar to how rebuildCounter
is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the test. The callback call in the previous message was hiding the fact that the cache didn't even have models.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the test! just have one suggestion, then I will merge
@@ -142,6 +142,12 @@ internal class PagedListModelCache<T>( | |||
return modelCache as List<EpoxyModel<*>> | |||
} | |||
|
|||
fun clearModels() { | |||
(0 until modelCache.size).forEach { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a simpler approach would be modelCache.fill(null)
Thanks for updating - this looks ready. I'm concerned that there could be race conditions by calling this clear function on a different thread at the same time models are being built. I think it is ok to address that in a follow up task though, since we need to think about synchronization of the whole class. |
I'm almost sure there is already a race condition in model building (see #567). That would have to be addressed as a whole. |
PR for #583