Clang: Reduce database accesses

If we prefetch data from the database to the caches we reduce the database
transaction calls which are quite expensive.

Change-Id: I617a0d886807402e0a94291a913a77f989970b55
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2019-08-20 14:45:01 +02:00
parent 04f8ff6404
commit c174eb378a
47 changed files with 617 additions and 213 deletions

View File

@@ -79,6 +79,7 @@ protected:
NiceMock<MockFilePathStorage> mockStorage{mockDatabase};
Cache cache{mockStorage};
NiceMock<MockFilePathStorage> mockStorageFilled{mockDatabase};
Cache cacheNotFilled{mockStorageFilled};
};
TEST_F(FilePathCache, FilePathIdWithOutAnyEntryCallDirectoryId)
@@ -439,4 +440,51 @@ TEST_F(FilePathCache, UseTransactionIfAddingFilesOnlyInAddFilePathsCalls)
cacheFilled.addFilePaths(FilePathViews{"/path/to/file.h"});
}
TEST_F(FilePathCache, GetFileIdInAfterPopulateIfEmpty)
{
cacheNotFilled.populateIfEmpty();
auto id = cacheNotFilled.filePathId("/path2/to/file.cpp");
ASSERT_THAT(id, Eq(72));
}
TEST_F(FilePathCache, DontPopulateIfNotEmpty)
{
cacheNotFilled.filePathId("/path/to/file.cpp");
cacheNotFilled.populateIfEmpty();
auto id = cacheNotFilled.filePathId("/path2/to/file.cpp");
ASSERT_FALSE(id.isValid());
}
TEST_F(FilePathCache, GetDirectoryIdAfterPopulateIfEmpty)
{
cacheNotFilled.populateIfEmpty();
auto id = cacheNotFilled.directoryPathId(42);
ASSERT_THAT(id, Eq(5));
}
TEST_F(FilePathCache, GetDirectoryPathAfterPopulateIfEmpty)
{
cacheNotFilled.populateIfEmpty();
auto path = cacheNotFilled.directoryPath(5);
ASSERT_THAT(path, Eq("/path/to"));
}
TEST_F(FilePathCache, GetFilePathAfterPopulateIfEmptye)
{
cacheNotFilled.populateIfEmpty();
auto path = cacheNotFilled.filePath(42);
ASSERT_THAT(path, Eq("/path/to/file.cpp"));
}
} // namespace