I want to optimize a query in my application involving the loading of blobs, which are the most important data for the main functionality of the application. Currently, the query is slow due to the time it takes to load blobs from the database. I need a solution that significantly improves the performance of this query, ensuring that blobs are loaded efficiently and quickly.
This query uses flow in kotlin to return a list. It is about 40k records and each record has a blob, it takes around 16-17sec.
I don’t know if I’m making a mistake with my query, but this is how I access the blob.
val queryBuilder = QueryBuilder.select(
SelectResult.expression(Meta.id).`as`("metaId"),
SelectResult.property("type"),
SelectResult.property("template")
).from(DataSource.collection(db.defaultCollection!!).`as`("item"))
.where(Expression.property("type")
.`in`(*types.filterNotNull().map { Expression.intValue(it) }
.toTypedArray()))
val results = queryBuilder.execute().map { row ->
RegistryT(
type = row.getInt("type"),
template = row.getBlob("template")?.content,
metaId = row.getString("metaId")
)
}
I identify that the amount of time it is taking is due to this. I also understand that the blobs are stored in a different section of the database. But this data is needed.
template = row.getBlob("template")?.content,
I would like to know if there is any way I can improve this or if I’m wrong.
Issues:
- Slow Performance: The current query takes a long time due to blob loading.
- Importance of Blobs: Blobs are critical for the main functionality of the application, so improving their loading is essential.
- Need for Speed: It is crucial that the query is fast, as efficiency in data loading affects user experience and overall application performance.