perf(devin): read only the metadata fields the parser uses (#1726)

The sessions.db query returned each message's whole metadata blob and
parsed it in JS (617 MB on a real store) to use five fields. The query now
builds an object of just those fields; a missing or non-object metadata
still comes back NULL.
This commit is contained in:
Resham Joshi 2026-10-10 07:06:19 +02:00 • committed by GitHub
parent 02dff282a8
commit e7c67a6695
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -649,7 +649,13 @@ class DevinDbSessionParser implements SessionParser {
const rows = db.query<MessageNodeRow>(
`SELECT node_id, parent_node_id,
json_extract(chat_message, '$.role') AS role,
json_extract(chat_message, '$.metadata') AS metadata,
CASE WHEN json_type(chat_message, '$.metadata') = 'object'
THEN json_object(
'created_at', chat_message -> '$.metadata.created_at',
'generation_model', chat_message -> '$.metadata.generation_model',
'is_user_input', chat_message -> '$.metadata.is_user_input',
'request_id', chat_message -> '$.metadata.request_id',
'metrics', chat_message -> '$.metadata.metrics') END AS metadata,
(SELECT json_group_array(json_extract(value, '$.name'))
FROM json_each(chat_message, '$.tool_calls')) AS tool_names,
CASE WHEN json_extract(chat_message, '$.role') = 'user'