Skip to content

Commit

Permalink
Minor bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
happy-mammal committed Apr 20, 2021
1 parent 0254a65 commit 4433c89
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function execute(isRegular){
}
await updateIndexAtFirestore(articles,articles.length);
await dumpDataToDatabase(articles,articles.length);
articles=[];
console.log(`\n[SCRIPT MAIN EXECUTION STOPPED]===>${qdg(new Date(),'current')}`);
}

Expand Down Expand Up @@ -64,7 +65,7 @@ async function pushToDataArray(category,data){
var titleKeywords = await kwg.generateKeywords(await data.title);
var sets = new Set(descKeywords.concat(titleKeywords));
var keywords = Array.from(sets);
var uniqueId = data.publishedAt.split('-').join('').split(':').join('').split('Z').join(`-${generateUniqueId()}`);
var uniqueId = await data.publishedAt.split('-').join('').split(':').join('').split('Z').join(`-${generateUniqueId()}`);

var jsonObject = {
id:uniqueId,
Expand Down Expand Up @@ -99,7 +100,8 @@ async function updateIndexAtFirestore(data,length){
}else{
if(dataSize<=available){
for(var i=0;i<length;i++){
var key = data[i].id;
var key =data[i].id;
await sleep(500);
await indexstore.doc(currentindexstore).update({
[`articles.${key}`]:data[i].payload.keywords,
}).then(()=>{
Expand All @@ -124,8 +126,10 @@ async function updateIndexAtFirestore(data,length){
async function dumpDataToDatabase(data,length){

for(var i=0;i<length;i++){
var key = data[i].id;
var key= data[i].id;
await sleep(500);
await database.child("articles").child(key).set({
id: data[i].id,
title: data[i].payload.title,
description: data[i].payload.description,
content: data[i].payload.content,
Expand All @@ -135,6 +139,7 @@ async function dumpDataToDatabase(data,length){
source: data[i].payload.source,
source_url: data[i].payload.source_url,
category: data[i].payload.category,
keywords: data[i].payload.keywords
}).then(()=>{
console.log(`SUCCESS [ARTICLE NO.]=>${i} [ARTICLE ID.]=>${data[i].id}`);
}).catch((err)=>{
Expand Down

0 comments on commit 4433c89

Please sign in to comment.