Get a cached ProcessedQuery by id. Note: this call should never fail as it is required that the row_id exist in the database before this method is called. Exceptions may be thrown in the case of database corruption. The method caches the previously retrieved elemen
(self, row_id)
| 201 | |
| 202 | @lru_cache(maxsize=1) |
| 203 | def get(self, row_id): |
| 204 | """ |
| 205 | Get a cached ProcessedQuery by id. Note: this call should never fail as |
| 206 | it is required that the row_id exist in the database before this method |
| 207 | is called. Exceptions may be thrown in the case of database corruption. |
| 208 | |
| 209 | The method caches the previously retrieved element because it is common |
| 210 | for a set of iterators (examples and labels) to retrieve the same row_id |
| 211 | in sequence. The cache prevents extra db lookups in this case. |
| 212 | |
| 213 | Args: |
| 214 | row_id(integer): The unique id returned by QueryCache.key_to_row_id() or |
| 215 | QueryCache.put(). |
| 216 | Returns: |
| 217 | ProcessedQuery: The ProcessedQuery associated with the identifier. |
| 218 | """ |
| 219 | cursor = self.connection.cursor() |
| 220 | cursor.execute(""" |
| 221 | SELECT query FROM queries WHERE rowid=(?); |
| 222 | """, (row_id,)) |
| 223 | row = cursor.fetchone() |
| 224 | return ProcessedQuery.from_cache(json.loads(row[0])) |
| 225 | |
| 226 | def get_value(self, domain, intent, query_text): |
| 227 | row_id = self.key_to_row_id(self.get_key(domain, intent, query_text)) |