半径是否会影响 firebase 中 geofire-common 中地理查询的性能

问题描述 投票:0回答:1

// Find cities within 50km of London
const center = [51.5074, 0.1278];
const radiusInM = 50 * 1000;

// Each item in 'bounds' represents a startAt/endAt pair. We have to issue
// a separate query for each pair. There can be up to 9 pairs of bounds
// depending on overlap, but in most cases there are 4.
const bounds = geofire.geohashQueryBounds(center, radiusInM);
const promises = [];
for (const b of bounds) {
  const q = query(
    collection(db, 'cities'),
    orderBy('geohash'),
    startAt(b[0]),
    endAt(b[1]));

  promises.push(getDocs(q));
}

半径对地理查询的性能有影响吗? (代码示例取自 firebase 文档)。我对与定位文档相关的性能特别感兴趣,而不是将它们传输给客户。因为我正在考虑在 firebase 功能上进行这些操作,然后只传输三五个文档给客户端。

javascript firebase google-cloud-firestore geofire
1个回答
0
投票

Cloud Firestore 具有非常简单但独特的性能保证:任何查询的执行都取决于返回结果的数量(和大小),而不是需要考虑的文档数量。

因此,如果较大的区域导致 Firestore 必须返回更多文档,那么它会比返回较少文档的查询慢。但区域大小本身对其没有影响。

换句话说,如果您对同一个集合进行 10m 半径的查询,返回 100 个文档,则与对 1000m 半径的查询返回该集合中的 100 个文档所需的时间一样长。

© www.soinside.com 2019 - 2024. All rights reserved.