Skip to content
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

Merged
merged 4 commits into from
Jan 8, 2019
Merged

Added method to clear model cache and force a model build (#583) #586

merged 4 commits into from
Jan 8, 2019

Conversation

kakai248
Copy link
Contributor

PR for #583

@elihart
Copy link
Contributor

elihart commented Nov 10, 2018

Could you add a test for this? there are already a bunch for the paged controller

@kakai248
Copy link
Contributor Author

Yeah, I'll do it in the next days or weekend.

Copy link
Contributor

@elihart elihart left a 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()
Copy link
Contributor

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

Copy link
Contributor Author

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()
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@elihart elihart left a 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 {
Copy link
Contributor

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)

@elihart
Copy link
Contributor

elihart commented Jan 8, 2019

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.

@kakai248
Copy link
Contributor Author

kakai248 commented Jan 8, 2019

I'm almost sure there is already a race condition in model building (see #567). That would have to be addressed as a whole.

@elihart elihart merged commit 993e40a into airbnb:master Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants