| 597 | } |
| 598 | |
| 599 | bool SqliteCache::prune() { |
| 600 | CESIUM_TRACE("SqliteCache::prune"); |
| 601 | std::lock_guard<std::mutex> guard(this->_pImpl->_mutex); |
| 602 | |
| 603 | int64_t totalItems = 0; |
| 604 | |
| 605 | // query total size of response's data |
| 606 | { |
| 607 | int totalItemsQueryStatus = CESIUM_SQLITE(sqlite3_reset)( |
| 608 | this->_pImpl->_totalItemsQueryStmtWrapper.get()); |
| 609 | if (totalItemsQueryStatus != SQLITE_OK) { |
| 610 | SPDLOG_LOGGER_ERROR( |
| 611 | this->_pImpl->_pLogger, |
| 612 | CESIUM_SQLITE(sqlite3_errstr)(totalItemsQueryStatus)); |
| 613 | return false; |
| 614 | } |
| 615 | |
| 616 | totalItemsQueryStatus = CESIUM_SQLITE(sqlite3_clear_bindings)( |
| 617 | this->_pImpl->_totalItemsQueryStmtWrapper.get()); |
| 618 | if (totalItemsQueryStatus != SQLITE_OK) { |
| 619 | SPDLOG_LOGGER_ERROR( |
| 620 | this->_pImpl->_pLogger, |
| 621 | CESIUM_SQLITE(sqlite3_errstr)(totalItemsQueryStatus)); |
| 622 | return false; |
| 623 | } |
| 624 | |
| 625 | totalItemsQueryStatus = CESIUM_SQLITE(sqlite3_step)( |
| 626 | this->_pImpl->_totalItemsQueryStmtWrapper.get()); |
| 627 | |
| 628 | if (totalItemsQueryStatus == SQLITE_DONE) { |
| 629 | return true; |
| 630 | } |
| 631 | |
| 632 | if (totalItemsQueryStatus != SQLITE_ROW) { |
| 633 | if (totalItemsQueryStatus == SQLITE_CORRUPT) { |
| 634 | destroyDatabase(); |
| 635 | } |
| 636 | SPDLOG_LOGGER_ERROR( |
| 637 | this->_pImpl->_pLogger, |
| 638 | CESIUM_SQLITE(sqlite3_errstr)(totalItemsQueryStatus)); |
| 639 | return false; |
| 640 | } |
| 641 | |
| 642 | // prune the rows if over maximum |
| 643 | totalItems = CESIUM_SQLITE(sqlite3_column_int64)( |
| 644 | this->_pImpl->_totalItemsQueryStmtWrapper.get(), |
| 645 | 0); |
| 646 | if (totalItems > 0 && |
| 647 | totalItems <= static_cast<int64_t>(this->_pImpl->_maxItems)) { |
| 648 | return true; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | // delete expired rows first |
| 653 | { |
| 654 | int deleteExpiredStatus = CESIUM_SQLITE(sqlite3_reset)( |
| 655 | this->_pImpl->_deleteExpiredStmtWrapper.get()); |
| 656 | if (deleteExpiredStatus != SQLITE_OK) { |
no test coverage detected