Fix contributor website import script (#8404)
We had duplicate entries in the database for issueLabels/ prLabels
This commit is contained in:
@ -35,6 +35,7 @@ const insertMany = async (
|
|||||||
options?: {
|
options?: {
|
||||||
onConflictKey?: string;
|
onConflictKey?: string;
|
||||||
onConflictUpdateObject?: any;
|
onConflictUpdateObject?: any;
|
||||||
|
onConflictDoNothing?: boolean;
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
const query = pgDb.insert(model).values(data);
|
const query = pgDb.insert(model).values(data);
|
||||||
@ -50,6 +51,10 @@ const insertMany = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options?.onConflictDoNothing && !options?.onConflictKey) {
|
||||||
|
return query.onConflictDoNothing().execute();
|
||||||
|
}
|
||||||
|
|
||||||
if (options?.onConflictKey) {
|
if (options?.onConflictKey) {
|
||||||
return query
|
return query
|
||||||
.onConflictDoNothing({
|
.onConflictDoNothing({
|
||||||
|
|||||||
@ -9,7 +9,11 @@ export async function getLatestUpdate() {
|
|||||||
desc(pullRequestModel.updatedAt),
|
desc(pullRequestModel.updatedAt),
|
||||||
);
|
);
|
||||||
const latestIssue = await findOne(issueModel, desc(issueModel.updatedAt));
|
const latestIssue = await findOne(issueModel, desc(issueModel.updatedAt));
|
||||||
const prDate = new Date(latestPR[0].updatedAt);
|
const prDate = latestPR[0]
|
||||||
const issueDate = new Date(latestIssue[0].updatedAt);
|
? new Date(latestPR[0].updatedAt)
|
||||||
|
: new Date('2023-01-01');
|
||||||
|
const issueDate = latestIssue[0]
|
||||||
|
? new Date(latestIssue[0].updatedAt)
|
||||||
|
: new Date('2023-01-01');
|
||||||
return (prDate > issueDate ? prDate : issueDate).toISOString();
|
return (prDate > issueDate ? prDate : issueDate).toISOString();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,12 +82,18 @@ export async function saveIssuesToDB(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await insertMany(issueLabelModel, [
|
await insertMany(
|
||||||
|
issueLabelModel,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
issueId: issue.id,
|
||||||
|
labelId: label.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
{
|
{
|
||||||
pullRequestId: issue.id,
|
onConflictDoNothing: true,
|
||||||
labelId: label.id,
|
|
||||||
},
|
},
|
||||||
]);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,12 +85,18 @@ export async function savePRsToDB(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await insertMany(pullRequestLabelModel, [
|
await insertMany(
|
||||||
|
pullRequestLabelModel,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
pullRequestId: pr.id,
|
||||||
|
labelId: label.id,
|
||||||
|
},
|
||||||
|
],
|
||||||
{
|
{
|
||||||
pullRequestId: pr.id,
|
onConflictDoNothing: true,
|
||||||
labelId: label.id,
|
|
||||||
},
|
},
|
||||||
]);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export const executePartialSync = async () => {
|
|||||||
return new Error('No GitHub token provided');
|
return new Error('No GitHub token provided');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Synching data..');
|
console.log('Syncing data... (partial sync)');
|
||||||
|
|
||||||
const query = graphql.defaults({
|
const query = graphql.defaults({
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export const fetchAndSaveGithubData = async () => {
|
|||||||
return new Error('No GitHub token provided');
|
return new Error('No GitHub token provided');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Synching data..');
|
console.log('Syncing data...');
|
||||||
|
|
||||||
const query = graphql.defaults({
|
const query = graphql.defaults({
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Reference in New Issue
Block a user