|
9 | 9 | from arango.exceptions import (
|
10 | 10 | ArangoServerError,
|
11 | 11 | CollectionChecksumError,
|
| 12 | + CollectionCompactError, |
12 | 13 | CollectionConfigureError,
|
| 14 | + CollectionInformationError, |
13 | 15 | CollectionLoadError,
|
14 | 16 | CollectionPropertiesError,
|
15 | 17 | CollectionRecalculateCountError,
|
@@ -335,6 +337,26 @@ def response_handler(resp: Response) -> Json:
|
335 | 337 |
|
336 | 338 | return self._execute(request, response_handler)
|
337 | 339 |
|
| 340 | + def info(self) -> Result[Json]: |
| 341 | + """Return the collection information. |
| 342 | +
|
| 343 | + :return: Information about the collection. |
| 344 | + :rtype: dict |
| 345 | + :raise arango.exceptions.CollectionInformationError: If retrieval fails. |
| 346 | + """ |
| 347 | + request = Request( |
| 348 | + method="get", |
| 349 | + endpoint=f"/_api/collection/{self.name}", |
| 350 | + read=self.name, |
| 351 | + ) |
| 352 | + |
| 353 | + def response_handler(resp: Response) -> Json: |
| 354 | + if resp.is_success: |
| 355 | + return format_collection(resp.body) |
| 356 | + raise CollectionInformationError(resp, request) |
| 357 | + |
| 358 | + return self._execute(request, response_handler) |
| 359 | + |
338 | 360 | def configure(
|
339 | 361 | self,
|
340 | 362 | sync: Optional[bool] = None,
|
@@ -480,6 +502,35 @@ def response_handler(resp: Response) -> str:
|
480 | 502 |
|
481 | 503 | return self._execute(request, response_handler)
|
482 | 504 |
|
| 505 | + def compact(self) -> Result[Json]: |
| 506 | + """Compact a collection. |
| 507 | +
|
| 508 | + Compacts the data of a collection in order to reclaim disk space. |
| 509 | + The operation will compact the document and index data by rewriting the |
| 510 | + underlying .sst files and only keeping the relevant entries. |
| 511 | +
|
| 512 | + Under normal circumstances, running a compact operation is not necessary, as |
| 513 | + the collection data will eventually get compacted anyway. However, in some |
| 514 | + situations, e.g. after running lots of update/replace or remove operations, |
| 515 | + the disk data for a collection may contain a lot of outdated data for which the |
| 516 | + space shall be reclaimed. In this case the compaction operation can be used. |
| 517 | +
|
| 518 | + :return: Collection compact. |
| 519 | + :rtype: dict |
| 520 | + :raise arango.exceptions.CollectionCompactError: If retrieval fails. |
| 521 | + """ |
| 522 | + request = Request( |
| 523 | + method="put", |
| 524 | + endpoint=f"/_api/collection/{self.name}/compact", |
| 525 | + ) |
| 526 | + |
| 527 | + def response_handler(resp: Response) -> Json: |
| 528 | + if resp.is_success: |
| 529 | + return format_collection(resp.body) |
| 530 | + raise CollectionCompactError(resp, request) |
| 531 | + |
| 532 | + return self._execute(request, response_handler) |
| 533 | + |
483 | 534 | def load(self) -> Result[bool]:
|
484 | 535 | """Load the collection into memory.
|
485 | 536 |
|
|
0 commit comments