(self, num_rows: int, batch_size: int = 10000)
| 216 | logger.debug(f"Attempted to delete non-existing key: {key}") |
| 217 | |
| 218 | def _generate_test_data(self, num_rows: int, batch_size: int = 10000): |
| 219 | logger.info("Generating test data") |
| 220 | self.ensure_connection() |
| 221 | with self.connection: |
| 222 | # Fetch a random key-value pair just once |
| 223 | self.cursor.execute( |
| 224 | "SELECT key, value FROM cache ORDER BY RANDOM() LIMIT 1" |
| 225 | ) |
| 226 | key, value = self.cursor.fetchone() |
| 227 | |
| 228 | # Use a generator to create batches of test data |
| 229 | def data_generator(): |
| 230 | for i in range(num_rows): |
| 231 | yield (f"{uuid.uuid4()}", value) |
| 232 | |
| 233 | # Process data in batches |
| 234 | for offset in range(0, num_rows, batch_size): |
| 235 | batch = list(islice(data_generator(), batch_size)) |
| 236 | self.cursor.executemany("INSERT INTO cache VALUES (?, ?)", batch) |
| 237 | self.connection.commit() |
| 238 | print( |
| 239 | f"Inserted {min(offset + batch_size, num_rows)} / {num_rows} rows" |
| 240 | ) |
| 241 | |
| 242 | def maintenance(self, time: Optional[int] = None, blocking_time: float = 0.5): |
| 243 | connection = sqlite3.connect(self.database) |
nothing calls this directly
no test coverage detected