Firebase查询的返回时间差异很大

时间:2017-01-11 19:05:44

标签: ios swift firebase firebase-realtime-database

我正在使用Firebase在Swift中使用一个非常简单的CRUD应用程序。当我尝试对Firebase数据库进行基本查询时,请求有时会立即返回(<500毫秒)或者可能需要> 60秒才会返回,如果它完全返回的话。我的数据库设置非常传统,所以我不清楚为什么会发生这种情况。

代码

productRef = databaseRef?.child(CFXConstants.kProductsRefPath)
productRef?.queryLimited(toFirst: 100).observeSingleEvent(of: FIRDataEventType.value, with: { (dataSnapshot) in
        self.loadProducts(dataSnapshot: dataSnapshot)
    }, withCancel: { (error) in
        print("Error ", error)
    })

来自/ products

的JSON示例
 "products" : {
"07a0c1a0-a952-5aaa-89b5-0908449ab824" : {
  "altIDs" : {
    "ASIN" : "B004M5IS94",
    "UPC" : "870588005342"
  },
  "assets" : [ {
    "category" : "variant",
    "cdnBucket" : "colfax-1630b.appspot.com",
    "cdnPath" : "images/products/07a0c1a0-a952-5aaa-89b5-0908449ab824/31RPStvy0uL.jpg",
    "height" : 500,
    "url" : "https://images-na.ssl-images-amazon.com/images/I/31RPStvy0uL.jpg",
    "width" : 375
  }, {
    "category" : "primary",
    "cdnBucket" : "colfax-1630b.appspot.com",
    "cdnPath" : "images/products/07a0c1a0-a952-5aaa-89b5-0908449ab824/71FSsAJfRmL.jpg",
    "height" : 1943,
    "url" : "https://images-na.ssl-images-amazon.com/images/I/71FSsAJfRmL.jpg",
    "width" : 1525
  } ],
  "attributes" : {
    "color" : "Silver/Red"
  },
  "brand" : "Barbuzzo",
  "categories" : [ {
    "category" : "Kitchen",
    "typeName" : "KITCHEN"
  } ],
  "description" : [ "Fun game with friends.", "Shot glass is made out of glass" ],
  "id" : "07a0c1a0-a952-5aaa-89b5-0908449ab824",
  "name" : "Barbuzzo Spin-the-Shot",
  "price" : {
    "amount" : 572,
    "listPrice" : 999
  },
  "shipping" : {
    "isPrime" : true
  },
  "url" : "https://www.amazon.com/Barbuzzo-UTU3BR0114-Spin-the-Shot/dp/B004M5IS94%3Fpsc%3D1%26SubscriptionId%3DAKIAIB4A6LS2FSOLQSXQ%26tag%3Dcolfax-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB004M5IS94"
},
"3b62b56b-629e-54a8-8135-b18b9495ab2c" : {
  "altIDs" : {
    "ASIN" : "B0010O748Q",
    "UPC" : "706569055191"
  },
  "assets" : [ {
    "category" : "primary",
    "cdnBucket" : "colfax-1630b.appspot.com",
    "cdnPath" : "images/products/3b62b56b-629e-54a8-8135-b18b9495ab2c/31Ebv505WQL.jpg",
    "height" : 318,
    "url" : "https://images-na.ssl-images-amazon.com/images/I/31Ebv505WQL.jpg",
    "width" : 500
  }, {
    "category" : "variant",
    "cdnBucket" : "colfax-1630b.appspot.com",
    "cdnPath" : "images/products/3b62b56b-629e-54a8-8135-b18b9495ab2c/31QU5imXRoL.jpg",
    "height" : 500,
    "url" : "https://images-na.ssl-images-amazon.com/images/I/31QU5imXRoL.jpg",
    "width" : 148
  }, {
    "category" : "variant",
    "cdnBucket" : "colfax-1630b.appspot.com",
    "cdnPath" : "images/products/3b62b56b-629e-54a8-8135-b18b9495ab2c/51-RbWnQyhL.jpg",
    "height" : 354,
    "url" : "https://images-na.ssl-images-amazon.com/images/I/51-RbWnQyhL.jpg",
    "width" : 500
  } ],
  "attributes" : {
    "color" : "Silver"
  },
  "brand" : "SE",
  "categories" : [ {
    "category" : "Home Improvement",
    "typeName" : "TOOLS"
  } ],
  "description" : [ "Compact pocket size", "Waterproof & weatherproof", "3\" x 1\" Solid magnesium bar with flint", "Single-sided serrated striker", "Bonus items: Compass & Detachable ball chain" ],
  "id" : "3b62b56b-629e-54a8-8135-b18b9495ab2c",
  "name" : "SE FS374 All-Weather Emergency 2-IN-1 Fire Starter & Magnesium Fuel Bar (Everything you need to start a fire!)",
  "price" : {
    "amount" : 300,
    "listPrice" : 699
  },
  "shipping" : {
    "isPrime" : true
  },
  "url" : "https://www.amazon.com/SE-FS374-All-Weather-Emergency-Everything/dp/B0010O748Q%3FSubscriptionId%3DAKIAIB4A6LS2FSOLQSXQ%26tag%3Dcolfax-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0010O748Q"
},

0 个答案:

没有答案