Skip to content

ssbc: Persist cache result on workspace

Administrator requested to merge es/fix-caching into main

Created by: eseliger

This PR fixes https://github.com/sourcegraph/sourcegraph/issues/28080.

Before, we would lose cached status on steps when the cache is evicted. Also, when using the noCache option, we would still show step cache results briefly in the UI. This PR also enforces that we have step cache results available for all steps before the most recent cache result (before, we could have a result for step 3, but none for 1 and 2 and those would render incorrectly and have no diff etc).

The downside: This duplicates a lot of data. This might become problematic in the future. This is a really easy and straightforward fix and I don't anticipate anyone before GA running into big trouble here, but if we think this is a big blocker, we can address this now as well. An alternative solution would be to only store the link between step and cache result, as a foreign key. We could add a table workspace_step_cache_entries (workspace_id, cache_entry_id).

Then we would need to adjust our pruning algorithm:

  • We don't count referenced cache entries in the total cache size when we calculate what to prune
  • We do allow duplicates in the key column
    • and when reading cache entries for use, we do SELECT max(id) .. GROUP BY key
    • when inserting a new cache entry we
      • insert as before when there's no collision
      • update the record in place, when there are 0 references to this entry
      • create a new record

If we decide to proceed with this approach for now, because it fixes the issue at some additional storage cost, I'll put this PR description in a ticket for post beta work. Otherwise, I'll pick this up again and incorporate these suggestions into this PR. I don't have a strong preference but would err on the side of moving fast.

Merge request reports

Loading