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
Fixes #17568: Allow to regenerate generic methods when there is a new one #3024
Conversation
@@ -53,11 +53,27 @@ class TechniqueReader( | |||
} | |||
} | |||
|
|||
def doesMethodsMetadataFileNeedsUpdate ={ | |||
def getCfFilesInDir(file : File): Iterator[File] = { | |||
if (file.isDirectory) { |
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.
why not file.collectChildren(your extension filter)
?
|
||
val methodsFileModifiedTime = methodsFile.lastModifiedTime() | ||
|
||
(getCfFilesInDir(baseDir) ++ getCfFilesInDir(userDir)).map{_.lastModifiedTime()}.exists(_.isAfter(methodsFileModifiedTime)) |
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.
That seems inefficient. You could either collect directly max time when you iterate on childrens (map is not lazy, so you will go through all children for it), or even pass the comparison date in your collect's filter so that you just have to check for iterator.nonEmpty
(which should stop on first match)
PR updated with a new commit |
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 the logic is OK and you can self merge. I added a comment to help you see how you could make the code easier to test, but it's not a required change, I let you decide.
val baseDir = root / "usr" / "share" / "ncf" / "tree" / "30_generic_methods" | ||
val userDir = configuration_repository / "ncf" / "30_generic_methods" | ||
baseDir.collectChildren(isAMethodNewerThanCache).isEmpty || userDir.collectChildren(isAMethodNewerThanCache).isEmpty | ||
} |
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 it's ok but it's hard to test as it is. What would make it easier to test is to have it split in two:
- one part with the logic and parameters for all states,
- one methods that set state for user convenience, ie:
// this one contains logic but stateless and so easy to test - actually, we could make it pure
// with an `IORestul.effect` around last statement
private[this] def checkNeedsUpdate(lastTime: TimeType, dirs: List[File]) : Boolean = {
def isAMethodNewerThanCache(file : File) : Boolean = {
file.isRegularFile && file.extension(false).map(_ == "cf").getOrElse(false) && lastTime.isAfter(methodsFileModifiedTime)
}
dirs.exist(dir => dir.collectChildren(isAMethodNewerThanCache).isEmpty)
}
// this one is convenient and meaningful to use in the code (but untestable)
private[this] def doesMethodsMetadataFileNeedsUpdate : Boolean = {
val methodsFileModifiedTime = methodsFile.lastModifiedTime()
val baseDir = root / "usr" / "share" / "ncf" / "tree" / "30_generic_methods"
val userDir = configuration_repository / "ncf" / "30_generic_methods"
checkNeedsUpdate(methodsFileModifiedTime, baseDir :: userDir :: Nil)
}
PR updated with a new commit |
for { | ||
metadataFileExists <- IOResult.effect(methodsFile.exists) | ||
needsUpdate <- if (metadataFileExists) { | ||
val methodsFileModifiedTime = methodsFile.lastModifiedTime() |
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.
this is an IO too :)
PR updated with a new commit |
This PR is not mergeable to upper versions. |
OK, squash merging this PR |
70d863c
to
188cff0
Compare
https://issues.rudder.io/issues/17568