- Fixing query to reduce the amount of processing on the code side

pull/38/head
Matheus Lima 2019-02-05 11:09:23 -03:00
parent 3f988221f3
commit 0b01fdbe97
2 changed files with 3 additions and 17 deletions

View File

@ -20,16 +20,7 @@ def get_device_by_id(db, device_id: str) -> Device:
singleton=True
)
sql_results = fetch(db, query)
device = {k: v for k, v in sql_results.items() if k in ('id', 'name', 'platform', 'enclosure_version', 'core_version')}
wake_word = {k: v for k, v in sql_results.items() if k in ('wake_word_id', 'wake_word', 'engine')}
wake_word['id'] = wake_word.pop('wake_word_id')
device['wake_word'] = wake_word
text_to_speech = {k: v for k, v in sql_results.items() if k in ('text_to_speech_id', 'setting_name', 'display_name', 'engine')}
text_to_speech['id'] = text_to_speech.pop('text_to_speech_id')
device['text_to_speech'] = text_to_speech
return Device(**device)
return Device(**sql_results)
def get_devices_by_account_id(db, account_id: str) -> List[Device]:

View File

@ -5,13 +5,8 @@ SELECT
dev.enclosure_version,
dev.core_version,
dev.placement,
wk_word.id as wake_word_id,
wk_word.wake_word,
wk_word.engine,
tts.id as text_to_speech_id,
tts.setting_name,
tts.display_name,
tts.engine
json_build_object('id', wk_word.id, 'wake_word', wk_word.wake_word, 'engine', wk_word.engine) as wake_word,
json_build_object('id', tts.id, 'setting_name', tts.setting_name, 'display_name', tts.display_name, 'engine', tts.engine) as text_to_speech
FROM device.device dev
INNER JOIN
device.wake_word wk_word ON dev.wake_word_id = wk_word.id