Navigation Menu

Skip to content

Commit

Permalink
Fixing that the Fingerprint column was too big for an index
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Apr 2, 2015
1 parent 635a188 commit bf20609
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
31 changes: 24 additions & 7 deletions Migrations.cs
Expand Up @@ -24,7 +24,7 @@ public int Create()
SchemaBuilder.CreateTable(typeof(CombinedFileRecord).Name,
table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<string>("Fingerprint", column => column.NotNull().WithLength(1024))
.Column<string>("Fingerprint", column => column.NotNull().WithLength(50))
.Column<int>("Slice")
.Column<string>("Type")
.Column<DateTime>("LastUpdatedUtc")
Expand All @@ -36,7 +36,7 @@ public int Create()
);


return 13;
return 14;
}

public int UpdateFrom1()
Expand Down Expand Up @@ -149,17 +149,14 @@ public int UpdateFrom8()

public int UpdateFrom9()
{
// Changing cache file folder
_cacheFileService.Empty();

// Cache empty call removed as it causes exception with certain versions.

return 10;
}

public int UpdateFrom10()
{
// Cache files are now in a hidden folder in Media
_cacheFileService.Empty();
// Cache empty call removed as it causes exception with certain versions.


return 11;
Expand Down Expand Up @@ -191,6 +188,26 @@ public int UpdateFrom12()
return 13;
}

public int UpdateFrom13()
{
// Cannot alter a column that is part of a key or an index.
SchemaBuilder.AlterTable(typeof(CombinedFileRecord).Name,
table => table.DropIndex("FileFingerprint")
);

SchemaBuilder.AlterTable(typeof(CombinedFileRecord).Name,
table => table.AlterColumn("Fingerprint", column => column.WithType(DbType.String).WithLength(50))
);

SchemaBuilder.AlterTable(typeof(CombinedFileRecord).Name,
table => table
.CreateIndex("FileFingerprint", new[] { "Fingerprint" })
);


return 14;
}


public void Uninstall()
{
Expand Down
13 changes: 9 additions & 4 deletions Services/CacheFileService.cs
Expand Up @@ -76,11 +76,11 @@ public void Save(string fingerprint, CombinatorResource resource, Uri resourceBa
return;
}

var sliceCount = _fileRepository.Count(file => file.Fingerprint == fingerprint);
var sliceCount = _fileRepository.Count(file => file.Fingerprint == ConvertFingerprintToStorageFormat(fingerprint));

var fileRecord = new CombinedFileRecord()
{
Fingerprint = fingerprint,
Fingerprint = ConvertFingerprintToStorageFormat(fingerprint),
Slice = ++sliceCount,
Type = resource.Type,
LastUpdatedUtc = _clock.UtcNow,
Expand Down Expand Up @@ -139,7 +139,7 @@ public IList<CombinatorResource> GetCombinedResources(string fingerprint, bool u
_combinatorEventMonitor.MonitorCacheEmptied(cacheKey);
_combinatorEventMonitor.MonitorBundleChanged(cacheKey, fingerprint);
var files = _fileRepository.Fetch(file => file.Fingerprint == fingerprint).ToList();
var files = _fileRepository.Fetch(file => file.Fingerprint == ConvertFingerprintToStorageFormat(fingerprint)).ToList();
var fileCount = files.Count;
var resources = new List<CombinatorResource>(fileCount);
Expand Down Expand Up @@ -181,7 +181,7 @@ public bool Exists(string fingerprint, bool useResourceShare)
_combinatorEventMonitor.MonitorCacheEmptied(cacheKey);
_combinatorEventMonitor.MonitorBundleChanged(cacheKey, fingerprint);
// Maybe also check if the file exists?
return _fileRepository.Count(file => file.Fingerprint == fingerprint) != 0;
return _fileRepository.Count(file => file.Fingerprint == ConvertFingerprintToStorageFormat(fingerprint)) != 0;
});
}

Expand Down Expand Up @@ -261,5 +261,10 @@ private static string MakeCacheKey(string name)
{
return CachePrefix + name;
}

private static string ConvertFingerprintToStorageFormat(string fingerprint)
{
return fingerprint.GetHashCode().ToString();
}
}
}

0 comments on commit bf20609

Please sign in to comment.