Javascript code too slow in Firefox extension using Storage service

前端 未结 3 1233
南笙
南笙 2021-01-26 02:45

I\'m running the following javascript code in firefox extension

highlightLinks: function(e) {

  var anchors = e.target.getElementsByTagName(\"a\");
  let file =         


        
3条回答
  •  一个人的身影
    2021-01-26 03:15

    In general when you call a database(not the browser ones) it is better to make one call, fetch all the data you will need into an array or an hash, and then work with them internally.

    EDIT:

    I would do that: load from the storage all the links and build a hash like:

    linksHash = {
      'url-1':true,
       ...,
      'url-n':true
    }
    

    Then loop on anchors and make a check with something like:

    if(linksHash[anchors[i].href]){
     //the link href is in the hash
    }
    

    Then if you note the RAM becomes an issue cut the load of the table in 2 or more pieces.

提交回复
热议问题