Exemplo n.º 1
0
  private void updateFilenameHistoryCache() {
    // TODO [medium] Performance: This throws away the unchanged entries. It should only update new
    // database version
    filenameHistoryCache.clear();

    for (PartialFileHistory cacheFileHistory : fullDatabaseVersionCache.getFileHistories()) {
      FileVersion lastVersion = cacheFileHistory.getLastVersion();
      String fileName = lastVersion.getPath();

      if (lastVersion.getStatus() != FileStatus.DELETED) {
        filenameHistoryCache.put(fileName, cacheFileHistory);
      }
    }
  }
Exemplo n.º 2
0
  // TODO [medium] Very inefficient. Always updates whole cache
  private void updateContentChecksumCache() {
    contentChecksumFileHistoriesCache.clear();

    for (PartialFileHistory fullFileHistory : fullDatabaseVersionCache.getFileHistories()) {
      FileChecksum lastVersionChecksum = fullFileHistory.getLastVersion().getChecksum();

      if (lastVersionChecksum != null) {
        List<PartialFileHistory> historiesWithVersionsWithSameChecksum =
            contentChecksumFileHistoriesCache.get(lastVersionChecksum);

        // Create if it does not exist
        if (historiesWithVersionsWithSameChecksum == null) {
          historiesWithVersionsWithSameChecksum = new ArrayList<PartialFileHistory>();
        }

        // Add to cache
        historiesWithVersionsWithSameChecksum.add(fullFileHistory);
        contentChecksumFileHistoriesCache.put(
            lastVersionChecksum, historiesWithVersionsWithSameChecksum);
      }
    }
  }
Exemplo n.º 3
0
  private void updateFullDatabaseVersionCache(DatabaseVersion newDatabaseVersion) {
    // Chunks
    for (ChunkEntry sourceChunk : newDatabaseVersion.getChunks()) {
      if (fullDatabaseVersionCache.getChunk(sourceChunk.getChecksum()) == null) {
        fullDatabaseVersionCache.addChunk(sourceChunk);
      }
    }

    // Multichunks
    for (MultiChunkEntry sourceMultiChunk : newDatabaseVersion.getMultiChunks()) {
      if (fullDatabaseVersionCache.getMultiChunk(sourceMultiChunk.getId()) == null) {
        fullDatabaseVersionCache.addMultiChunk(sourceMultiChunk);
      }
    }

    // Contents
    for (FileContent sourceFileContent : newDatabaseVersion.getFileContents()) {
      if (fullDatabaseVersionCache.getFileContent(sourceFileContent.getChecksum()) == null) {
        fullDatabaseVersionCache.addFileContent(sourceFileContent);
      }
    }

    // Histories
    for (PartialFileHistory sourceFileHistory : newDatabaseVersion.getFileHistories()) {
      PartialFileHistory targetFileHistory =
          fullDatabaseVersionCache.getFileHistory(sourceFileHistory.getFileId());

      if (targetFileHistory == null) {
        fullDatabaseVersionCache.addFileHistory((PartialFileHistory) sourceFileHistory.clone());
      } else {
        for (FileVersion sourceFileVersion : sourceFileHistory.getFileVersions().values()) {
          if (targetFileHistory.getFileVersion(sourceFileVersion.getVersion()) == null) {
            targetFileHistory.addFileVersion(sourceFileVersion);
          }
        }
      }
    }
  }