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

Bust cache for draft files when file exists on S3 #3052

Merged
merged 2 commits into from
May 8, 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
1 change: 1 addition & 0 deletions packages/openneuro-server/src/cache/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export enum CacheType {
snapshotIndex = "snapshotIndex",
participantCount = "participantCount",
snapshotDownload = "download",
draftRevision = "revision",
}
21 changes: 13 additions & 8 deletions packages/openneuro-server/src/datalad/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
import request from "superagent"
import Dataset from "../models/dataset"
import { getDatasetWorker } from "../libs/datalad-service"
import CacheItem, { CacheType } from "../cache/item"
import { redis } from "../libs/redis"

export const getDraftRevision = async (datasetId) => {
const draftUrl = `http://${
getDatasetWorker(
datasetId,
)
}/datasets/${datasetId}/draft`
const response = await fetch(draftUrl)
const { hexsha } = await response.json()
return hexsha
const cache = new CacheItem(redis, CacheType.draftRevision, [datasetId], 10)
return cache.get(async (_doNotCache): Promise<string> => {
const draftUrl = `http://${
getDatasetWorker(
datasetId,
)
}/datasets/${datasetId}/draft`
const response = await fetch(draftUrl)
const { hexsha } = await response.json()
return hexsha
})

Check warning on line 21 in packages/openneuro-server/src/datalad/draft.ts

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-server/src/datalad/draft.ts#L11-L21

Added lines #L11 - L21 were not covered by tests
}

export const updateDatasetRevision = (datasetId, gitRef) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/openneuro-server/src/handlers/datalad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mime from "mime-types"
import { getFiles } from "../datalad/files"
import { getDatasetWorker } from "../libs/datalad-service"
import { getDraftRevision } from "../datalad/draft"

Check warning on line 6 in packages/openneuro-server/src/handlers/datalad.ts

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-server/src/handlers/datalad.ts#L6

Added line #L6 was not covered by tests

/**
* Handlers for datalad dataset manipulation
Expand All @@ -21,7 +22,9 @@
const worker = getDatasetWorker(datasetId)
// Find the right tree
const pathComponents = filename.split(":")
let tree = snapshotId || "HEAD"
// Get the draft commit for cache busting
const draftCommit = await getDraftRevision(datasetId)
let tree = snapshotId || draftCommit

Check warning on line 27 in packages/openneuro-server/src/handlers/datalad.ts

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-server/src/handlers/datalad.ts#L25-L27

Added lines #L25 - L27 were not covered by tests
let file
for (const level of pathComponents) {
try {
Expand Down
Loading