Flushes data from the in-memory cache into the disk-backed cache
(self)
| 88 | self.batch_writes = None |
| 89 | |
| 90 | def flush_to_disk(self): |
| 91 | """ |
| 92 | Flushes data from the in-memory cache into the disk-backed cache |
| 93 | """ |
| 94 | logger.info("Flushing %s queries from in-memory cache to disk", len(self.batch_writes)) |
| 95 | rows = self.memory_connection.execute(f""" |
| 96 | SELECT hash_id, query, raw_query, domain, intent FROM queries |
| 97 | WHERE rowid IN ({",".join(self.batch_writes)}); |
| 98 | """) |
| 99 | self.disk_connection.executemany(""" |
| 100 | INSERT OR IGNORE into queries values (?, ?, ?, ?, ?); |
| 101 | """, rows) |
| 102 | self.disk_connection.commit() |
| 103 | self.batch_writes = [] |
| 104 | |
| 105 | def __del__(self): |
| 106 | if self.memory_connection and self.batch_writes: |