Skip to content

Commit

Permalink
fix: Ensure updatedAt is current when publishing changes
Browse files Browse the repository at this point in the history
Occasionally the GitHub API will return an old value for `updatedAt` if we sync too quickly after pushing a change.  This change overrides that value whenever we sync after publishing, and uses the current timestamp rather than the GitHub API value.
  • Loading branch information
baumandm committed Jan 3, 2022
1 parent 019cbb7 commit 5ffc660
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/backend/src/lib/backends/github.sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ export const githubRepositorySync = async (
// Load insight details from GitHub metadata
const insight = await getInsightFromRepository(item.owner, item.repo);

if (item.updated) {
// If this flag is set, it means an update was just pushed.
// Sometimes, the GitHub API hasn't recognized the update yet, so we
// need to manually update the updatedAt field to now.
insight.updatedAt = insight.syncedAt;
}

// Short-circuit if the repository is archived
if (insight.repository.isArchived) {
logger.warn(`[GITHUB_SYNC] This repository is archived; stopping sync`);
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/models/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ export interface InsightSyncTask {
* visible after indexing.
*/
refresh?: boolean;

/**
* Optional flag that indicates the repository was just updated.
*
* If true, the sync task will use the current time as the `updatedAt` field,
* rather than the repository's `updatedAt` field value.
*
* This avoids any potential sychronization issues with the repository.
*/
updated?: boolean;
}
3 changes: 2 additions & 1 deletion packages/backend/src/resolvers/insight.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ export class InsightResolver {
owner: repository.owner.login,
repo: repository.externalName,
repositoryType: RepositoryType.GITHUB,
refresh: true
refresh: true,
updated: true
})) as Insight;

// Log activity
Expand Down

0 comments on commit 5ffc660

Please sign in to comment.