MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / prune

Method prune

CesiumAsync/src/SqliteCache.cpp:599–739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

597}
598
599bool 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) {

Callers 1

getMethod · 0.45

Calls 2

CESIUM_SQLITEClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected