This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Cache voll?
#1
Hallo zusammen,
ich versuche gerade mit js meine Datenbank zu aktualisieren, indem ich in eine  Spalte neue Einträge reinschreibe. Um die benötigten Daten zu laden und später zu schreiben benutze ich fetch. Die Funktion funktioniert auch. Das Problem sind nur die vielen Einträge. Ich glaube da ich fetch benutze und so viele Daten asynchron lade, wird mein Arbeitspeicher schnell voll. Meine Frage ist jetzt, wie kann ich die for Schleife verändern, damit der Speicher nicht vollläuft. Kann ich z.B. den 1. fetch Befehl  irgendwie synchron laden?
Vielen Dank für eure Hilfe

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>

<script>

//wikiCode = "Q47554";




 
  errors = [];
  sucesses = 0;
  const params = new FormData();
  for (let i = 0; i < 880000; i++) {
        params.append('post_var1', i);
fetch("getWiki2Attractions3.php", {
            method: 'post',
            body: params
        }).then(res => {
            return res.text();
        }).then(res => {
            //console.log(res)
            output = JSON.parse(res)
            //console.log(output)
           
              
                
            
                //console.log(i)
            //console.log(output.towns[0].wikidata)
            if (output.towns.length == 0){errors.push(i)}
            wikiCode = output.towns[0].wikidata
            console.log(wikiCode)
            getSrcImage(wikiCode)
       
        
          
        })
   
//getSrcImage(wikiCode)

function getSrcImage(wikiCode){
    strImageAdd1 = "https://www.wikidata.org/wiki/Special:EntityData/"
    strImageAdd2 = ".json"
    //wikiCode = "Q3005760"
    strImageAdd = strImageAdd1 + wikiCode + strImageAdd2
   // console.log(strImageAdd)
    // console.log(outputWikiData)
     //prefix = "https://www.wikidata.org/wiki/"
     //prefix3 = "#/media/File:";
     //srcWikiData = prefix + wikiCode + prefix3 //+ outputWikiData
     //srcWikiData = prefix + wikiCode;
     //srcWikiData = "https://www.wikidata.org/wiki/Q6520258#/media/File:Leiston%20Abbey%20-Suffolk-3.jpg"
 
     //https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/Leiston_Abbey_-Suffolk-3.jpg/1280px-Leiston_Abbey_-Suffolk-3.jpg
 
      
     fetch(strImageAdd, {
            method: 'post',
            
        }).then(res => {
            return res.text();
        }).then(res => {
            output = JSON.parse(res) 
        //console.log(output)
        console.log(output.entities[wikiCode].claims.P18[0])
        if(output.entities[wikiCode].claims.hasOwnProperty("P18")){
        outputWikiData = output.entities[wikiCode].claims.P18[0].mainsnak.datavalue.value;
        
        console.log(outputWikiData)

        prefix = "https://www.wikidata.org/wiki/"
    prefix3 = "#/media/File:";
    srcWikiData = prefix + wikiCode + prefix3 + outputWikiData
    console.log(srcWikiData)
    srcWikiData = srcWikiData.replaceAll(" ", "_");
    //srcWikiData = "https://www.wikidata.org/wiki/Q6520258#/media/File:Leiston%20Abbey%20-Suffolk-3.jpg"
console.log(srcWikiData)
console.log(typeof(srcWikiData))
const params = new FormData();
  
        params.append('post_var1', srcWikiData);
    
    php_function = "wikiDataConvertLink.php"
    fetch(php_function, {
            method: 'post',
            body: params
        }).then(res => {
            return res.text();
        }).then(res => {
            console.log(res)
            const params = new FormData();
  
  params.append('post_var2', srcWikiData);
  params.append('post_var1', wikiCode);
       
  fetch("writeWiki2srcAttractions.php", {
            method: 'post',
            body: params
        }).then(res => {
            return res.text();
        }).then(res => {
            if (res.includes("Error")){errors.push(i),console.log(res)}
            console.log(res)
            console.log("sucesses : ", sucesses = sucesses +1, ";errors", errors)
        console.log(j = j+1)
        
        })
        })

    }
    else{errors.push(i);console.log(errors)}
    })
          
   
   


 
 }
  }
  

</script>
Zitieren
#2
Was soll das den sein?
Warum machst du den 800000 Abfragen?
Was für Daten holst du da?
Warum holst du nicht alles mit einer abfrage?

Kannst du das mal online stellen und erklären, was das genau sein soll,
weil so ergibt, es keinen Sinn fast 1 Million Abfragen zu machen.

Falls du da irgendwelche Daten von einer Webseite holen willst, dann würde ich keine Schleife nehmen.
Ich würde erst eine Abfrage machen , warten bis die da ist und dann die nächste holen. Dann gibt es auch keine Probleme. Wenn du das so machst wird dir jede Browser abkacken
Hier sind alle meine Lösungen aus allen Foren. Ich helfe auch in Facebook-chat
Als Lösung markieren Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste