Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust Cache Restore Order #313

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ jobs:
gharun -C testworkflows/reusable-workflows-secrets-inherit-with-required-secrets -s TEST=topsecret -s OPT=testsec
gharun -C testworkflows/inherit_vars --var ACTIONS_STEP_DEBUG=true
gharun -C testworkflows/actions_artifacts_v4 -s ACTIONS_STEP_DEBUG=true -s ACTIONS_RUNNER_DEBUG=true --runner-version v2.311.0
gharun -C testworkflows/actions_artifacts_v4 -s ACTIONS_STEP_DEBUG=true -s ACTIONS_RUNNER_DEBUG=true
gharun -C testworkflows/cache-save-restore-order-tests -s ACTIONS_STEP_DEBUG=true -s ACTIONS_RUNNER_DEBUG=true
gharun --event azpipelines -C testworkflows/azpipelines/cross-repo-checkout -W testworkflows/azpipelines/cross-repo-checkout/pipeline.yml --local-repository az/containermatrix@main=testworkflows/azpipelines/containermatrix
gharun --event azpipelines -C testworkflows/azpipelines/typedtemplates -W testworkflows/azpipelines/typedtemplates/pipeline.yml
gharun --event azpipelines -C testworkflows/azpipelines/untypedtemplates -W testworkflows/azpipelines/untypedtemplates/pipeline.yml
Expand Down
15 changes: 3 additions & 12 deletions src/Runner.Server/Controllers/CacheController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,12 @@ public async Task<IActionResult> GetCacheEntry( string owner, string repo, [From
var repository = User.FindFirst("repository")?.Value ?? "Unknown/Unknown";
foreach(var cref in reference != defaultRef ? new [] { reference, defaultRef } : new [] { reference }) {
foreach (var item in a) {
var record = (from rec in _context.Caches where rec.Repo.ToLower() == repository.ToLower() && rec.Ref == cref && rec.Key.ToLower() == item.ToLower() && (rec.Version == null || rec.Version == "" || rec.Version == version) orderby rec.LastUpdated descending select rec).FirstOrDefault();
var record = (from rec in _context.Caches where rec.Repo.ToLower() == repository.ToLower() && rec.Ref == cref && rec.Key.ToLower() == item.ToLower() && (rec.Version == null || rec.Version == "" || rec.Version == version) orderby rec.LastUpdated descending select rec).FirstOrDefault()
?? (from rec in _context.Caches where rec.Repo.ToLower() == repository.ToLower() && rec.Ref == cref && rec.Key.ToLower().StartsWith(item.ToLower()) && (rec.Version == null || rec.Version == "" || rec.Version == version) orderby rec.LastUpdated descending select rec).FirstOrDefault();
if(record != null) {
return await Ok(new ArtifactCacheEntry{ cacheKey = item, scope = cref, creationTime = record.LastUpdated.ToLongDateString(), archiveLocation = new Uri(new Uri(ServerUrl), $"_apis/artifactcache/get/{record.Id}").ToString() });
return await Ok(new ArtifactCacheEntry{ cacheKey = record.Key, scope = cref, creationTime = record.LastUpdated.ToLongDateString(), archiveLocation = new Uri(new Uri(ServerUrl), $"_apis/artifactcache/get/{record.Id}").ToString() });
}
}
CacheRecord partialMatch = null;
foreach (var item in a) {
var record = (from rec in _context.Caches where rec.Repo.ToLower() == repository.ToLower() && rec.Ref == cref && rec.Key.ToLower().StartsWith(item.ToLower()) && (rec.Version == null || rec.Version == "" || rec.Version == version) orderby rec.LastUpdated descending select rec).FirstOrDefault();
if(record != null && (partialMatch == null || record.LastUpdated > partialMatch.LastUpdated)) {
partialMatch = record;
}
}
if(partialMatch != null) {
return await Ok(new ArtifactCacheEntry{ cacheKey = partialMatch.Key, scope = cref, creationTime = partialMatch.LastUpdated.ToLongDateString(), archiveLocation = new Uri(new Uri(ServerUrl), $"_apis/artifactcache/get/{partialMatch.Id}").ToString() });
}
}
return NoContent();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
push:
jobs:
testa:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- uses: actions/cache/save@v4
with:
path: .
key: ${{ runner.os }}-${{ github.run_id }}-3
- uses: actions/cache/save@v4
with:
path: .
key: ${{ runner.os }}-${{ github.run_id }}-3-1
- uses: actions/cache/restore@v4
id: cache
with:
path: .
key: ${{ runner.os }}-${{ github.run_id }}-3
- name: Assert that we got a cache hit
run: exit 1
if: steps.cache.outputs.cache-hit != 'true'
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
jobs:
testa:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- uses: actions/cache/save@v4
with:
path: .
key: ${{ runner.os }}-${{ github.run_id }}-3
- uses: actions/cache/save@v4
with:
path: .
key: ${{ runner.os }}-${{ github.run_id }}-3-1
- uses: actions/cache/restore@v4
id: cache
with:
path: .
key: -----------------------------------------------------------
restore-keys:
${{ runner.os }}-${{ github.run_id }}-3
- name: Assert that we got a cache hit
run: exit 1
if: steps.cache.outputs.cache-matched-key != format('{0}-{1}-3', runner.os, github.run_id)
Loading