【发布时间】:2017-12-20 01:01:31
【问题描述】:
/*** Define all functions here (Query)! ***/
function get_all_loc(){ //get all locs in array
ref = database.ref('locs/'); //get from -- > locs in db
ref.on('value', gotData, errData); // getData or error !
all_locs_arr = [] ; //empty array everytime button is clicked -> to show new query :P if db updated meanwhile ! silly :P
all_locs_str = ""; //empty str everytime button is clicked -> to show new query :P if db updated meanwhile ! silly :P
function gotData(data){
all_locs_arr = data.val(); console.log(all_locs_arr); //firebase func to get data from db , storing it in all_loc_arr
for(var loc_index=0; loc_index<all_locs_arr.length ; loc_index++){
all_locs_str += "<li class='class_loc' loc-id='"+loc_index+"' >"+all_locs_arr[loc_index]+"</li>";
//console.log(all_locs_str);// add all locs in string
}
get_raw_matrix();
}function errData(data){
console.log("db_error! locs !");
}
}
get_all_loc(); // call get_all_loc function to get all locations into array & str , early fetch
这是我从 firebase 查询数据的函数。
之后,all_locs_arr = data.val();,我正在做console.log(all_locs_arr),
对于数组(长度为 10,000),在控制台上打印需要 5 分钟以上。
它是一个字符串数组。数组中每个字符串的大小小于10。
为什么获取数据这么慢?难道我做错了什么?我是否获取了太多数据?
我没有执行任何搜索/排序,只是获取整个数据,仍然很慢。
【问题讨论】:
-
我认为我不应该获取所有数据,我应该使用
ref = database.ref('locs/' + something )
标签: javascript json firebase firebase-realtime-database