MCPcopy Create free account
hub / github.com/alpha-liu-01/SpeedyNote / cleanupThumbnailCache

Method cleanupThumbnailCache

source/core/NotebookLibrary.cpp:558–597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

556}
557
558void NotebookLibrary::cleanupThumbnailCache()
559{
560 QDir cacheDir(m_thumbnailCachePath);
561 if (!cacheDir.exists()) {
562 return;
563 }
564
565 // Get all PNG files with their info
566 QFileInfoList files = cacheDir.entryInfoList({"*.png"}, QDir::Files);
567
568 // Calculate total size
569 qint64 totalSize = 0;
570 for (const auto& fileInfo : files) {
571 totalSize += fileInfo.size();
572 }
573
574 // If under limit, no cleanup needed
575 if (totalSize <= MAX_CACHE_SIZE_BYTES) {
576 return;
577 }
578
579 // Sort by last modified time (oldest first for LRU eviction)
580 std::sort(files.begin(), files.end(),
581 [](const QFileInfo& a, const QFileInfo& b) {
582 return a.lastModified() < b.lastModified();
583 });
584
585 // Delete oldest files until under limit
586 for (const auto& fileInfo : files) {
587 if (totalSize <= MAX_CACHE_SIZE_BYTES) {
588 break;
589 }
590
591 qint64 fileSize = fileInfo.size();
592 if (QFile::remove(fileInfo.absoluteFilePath())) {
593 totalSize -= fileSize;
594 // CR-P.2: Removed qDebug for production code
595 }
596 }
597}
598
599// === Persistence ===
600

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected