Git Product home page Git Product logo

Comments (3)

MichaelSolati avatar MichaelSolati commented on July 16, 2024

Unfortunately the answer would be no. The library is based off of the official firebase geofire library and makes multiple queries around the area you selected as well as validates that it is really within the radius you provided. However the turn around time is fairly quick. What I would suggest is to wrap the response.send(result) in a setTimeout after maybe 4 seconds? (Maybe more??)

Then as the onKeyEnteredRegistration is fired push the results into the results array.

from geofirestore-js.

uturnr avatar uturnr commented on July 16, 2024

Here's my ugly solution.

I create a promise with a timer that cancels the query and resolves in 10000ms.
Every time key_entered is fired, I reset the timer to 500ms.
When ready fires, I reset the timer to 1000ms.

It needs work, but it my most reliable solution so far, and my function currently returns data for a location with 21 documents in about 1600ms (3700ms on a cold start), and for a location with 0 documents in about 1100ms.*

return new Promise(resolve => {
    const geoQuery = geoFirestore.query({
      center: geoPoint,
      radius: 30
    });

    let geoQueryTimer = setTimeout(() => {
      geoQuery.cancel();
      resolve()
    }, 10000 );

    const onKeyEnteredRegistration = geoQuery.on(
      'key_entered',
      (key, doc, distance) => {
        clearTimeout(geoQueryTimer);
	// do stuff with doc
	// push to array, etc
        geoQueryTimer = setTimeout(() => {
          geoQuery.cancel();
          resolve()
        }, 500 );
      }
    );

    const onReadyRegistration = geoQuery.on(
      'ready',
      () => {
        clearTimeout(geoQueryTimer);
        geoQueryTimer = setTimeout(() => {
          geoQuery.cancel();
          resolve()
        }, 1000 );
      }
    )

  }).then(() => {
    // return data
  });

*edit: Times when testing functions locally in functions shell.

from geofirestore-js.

graig12 avatar graig12 commented on July 16, 2024

What if you need to do another Firestore database call within the key_entred event? How do u suggest we do this.

from geofirestore-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.