dup check was not properly setup
This commit is contained in:
@@ -13,7 +13,7 @@ const upsertData = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const tableName = getTableName(date);
|
const tableName = getTableName(date);
|
||||||
console.log(`[...] Upserting ${data.length} entries into ${tableName}`);
|
console.log(`[...] Upserting ${data.length} entries into ${tableName}`);
|
||||||
const alreadyPresentIds = new Set();
|
const alreadyPresentIds = new Set<string>();
|
||||||
try {
|
try {
|
||||||
const [alreadyPresent] = await surreal.query<[string[]]>(
|
const [alreadyPresent] = await surreal.query<[string[]]>(
|
||||||
`select value id from type::table($tableName) where bookDate = $bookDate`,
|
`select value id from type::table($tableName) where bookDate = $bookDate`,
|
||||||
@@ -33,16 +33,7 @@ const upsertData = async (
|
|||||||
const oldEntries = [] as any[];
|
const oldEntries = [] as any[];
|
||||||
const newEntries = [] as BookingEntry[];
|
const newEntries = [] as BookingEntry[];
|
||||||
for (let entry of data) {
|
for (let entry of data) {
|
||||||
if (!alreadyPresentIds.has(entry.id)) {
|
if (alreadyPresentIds.has(`${tableName}:${entry.id}`)) {
|
||||||
newEntries.push({
|
|
||||||
...entry,
|
|
||||||
id: `${tableName}:${entry.id}`,
|
|
||||||
createdAt: new Date().toISOString(),
|
|
||||||
updatedAt: new Date().toISOString(),
|
|
||||||
bookDate: entry.bookDate.split(" ")[0],
|
|
||||||
requestId: entry.requestId ?? "",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
oldEntries.push({
|
oldEntries.push({
|
||||||
distributorId: entry.distributorId,
|
distributorId: entry.distributorId,
|
||||||
dealerId: entry.dealerId,
|
dealerId: entry.dealerId,
|
||||||
@@ -57,7 +48,16 @@ const upsertData = async (
|
|||||||
requestId: entry.requestId,
|
requestId: entry.requestId,
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
newEntries.push({
|
||||||
|
...entry,
|
||||||
|
id: `${tableName}:${entry.id}`,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
bookDate: entry.bookDate.split(" ")[0],
|
||||||
|
requestId: entry.requestId ?? "",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
`[+] Inserting ${newEntries.length} new entries into ${tableName}`,
|
`[+] Inserting ${newEntries.length} new entries into ${tableName}`,
|
||||||
@@ -65,7 +65,7 @@ const upsertData = async (
|
|||||||
|
|
||||||
// 5 to 25% of the total data length
|
// 5 to 25% of the total data length
|
||||||
let chunkSize = Math.floor(
|
let chunkSize = Math.floor(
|
||||||
Math.random() * (data.length * 0.25 - data.length * 0.05) +
|
Math.random() * (data.length * 0.2 - data.length * 0.05) +
|
||||||
data.length * 0.05,
|
data.length * 0.05,
|
||||||
);
|
);
|
||||||
if (chunkSize > 10_000) {
|
if (chunkSize > 10_000) {
|
||||||
|
|||||||
Reference in New Issue
Block a user