-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Log filter times during form entry #6573
base: master
Are you sure you want to change the base?
Changes from all commits
350ad4f
8eeb6e9
81e9990
4ea48f1
3a52431
75ec936
3e6a81c
4f75b6f
47be00d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
package org.odk.collect.android.formmanagement | ||
|
||
import android.os.Handler | ||
import android.os.Looper | ||
import org.javarosa.core.model.FormDef | ||
import org.javarosa.core.model.condition.EvaluationContext | ||
import org.javarosa.core.model.condition.FilterStrategy | ||
import org.javarosa.core.model.instance.DataInstance | ||
import org.javarosa.core.model.instance.TreeReference | ||
import org.javarosa.form.api.FormEntryController | ||
import org.javarosa.form.api.FormEntryModel | ||
import org.javarosa.xpath.expr.XPathExpression | ||
import org.odk.collect.android.application.Collect | ||
import org.odk.collect.android.dynamicpreload.ExternalDataManagerImpl | ||
import org.odk.collect.android.dynamicpreload.handler.ExternalDataHandlerPull | ||
import org.odk.collect.android.tasks.FormLoaderTask.FormEntryControllerFactory | ||
import org.odk.collect.androidshared.ui.ToastUtils | ||
import org.odk.collect.entities.javarosa.filter.LocalEntitiesFilterStrategy | ||
import org.odk.collect.entities.javarosa.filter.PullDataFunctionHandler | ||
import org.odk.collect.entities.javarosa.finalization.EntityFormFinalizationProcessor | ||
import org.odk.collect.entities.storage.EntitiesRepository | ||
import org.odk.collect.settings.keys.ProjectKeys | ||
import org.odk.collect.shared.settings.Settings | ||
import java.io.File | ||
import java.util.function.Supplier | ||
|
||
class CollectFormEntryControllerFactory( | ||
private val entitiesRepository: EntitiesRepository, | ||
|
@@ -26,9 +36,40 @@ class CollectFormEntryControllerFactory( | |
|
||
return FormEntryController(FormEntryModel(formDef)).also { | ||
val externalDataHandlerPull = ExternalDataHandlerPull(externalDataManager) | ||
it.addFunctionHandler(PullDataFunctionHandler(entitiesRepository, externalDataHandlerPull)) | ||
it.addFunctionHandler( | ||
PullDataFunctionHandler( | ||
entitiesRepository, | ||
externalDataHandlerPull | ||
) | ||
) | ||
it.addPostProcessor(EntityFormFinalizationProcessor()) | ||
|
||
if (settings.getBoolean(ProjectKeys.KEY_DEBUG_FILTERS)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's convenient for the QA team or us to enable that option every time we install a new version of the app, which might happen quite often. Wouldn't it be better to always use that strategy in debug mode? |
||
it.addFilterStrategy(LoggingFilterStrategy()) | ||
} | ||
|
||
it.addFilterStrategy(LocalEntitiesFilterStrategy(entitiesRepository)) | ||
} | ||
} | ||
} | ||
|
||
private class LoggingFilterStrategy : FilterStrategy { | ||
override fun filter( | ||
sourceInstance: DataInstance<*>, | ||
nodeSet: TreeReference, | ||
predicate: XPathExpression, | ||
children: MutableList<TreeReference>, | ||
evaluationContext: EvaluationContext, | ||
next: Supplier<MutableList<TreeReference>> | ||
): MutableList<TreeReference> { | ||
val startTime = System.currentTimeMillis() | ||
val result = next.get() | ||
|
||
val filterTime = System.currentTimeMillis() - startTime | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can take advantage of
|
||
Handler(Looper.getMainLooper()).post { | ||
ToastUtils.showShortToast("Filter took ${filterTime / 1000.0}s") | ||
} | ||
|
||
return result | ||
} | ||
} |
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 can simplify this class even more by not passing the
application
param betweenshowToast
functions and just using it directly whereToast.makeText
is called.