GodotNuts / GodotFirebase

Implementations of Firebase for Godot using GDScript
MIT License
558 stars 79 forks source link

[FEATURE REQUEST] Listen to remote changes on a document #419

Closed theSlyest closed 4 months ago

theSlyest commented 4 months ago

The project already includes a FirestoreListener class for listening to document changes, but it only works for local changes. It should be able to listen to remote changes as well.

theSlyest commented 4 months ago

Already made the necessary updates locally. 😉

WolfgangSenff commented 4 months ago

Hm? It works for remote changes. It's just really expensive, so it's not on by default.

theSlyest commented 4 months ago

Okay. Maybe I didn't do it correctly.

    var collection: FirestoreCollection = Firebase.Firestore.collection(collection_id)
    var document: FirestoreDocument = await collection.get_doc(document_id)
    _doc_connect = document.on_snapshot(on_document_updated)

I've noticed that FirestoreDocument.collection_name is never assigned, but is used to initialize FirestoreListener and so FirestoreListener requests don't work.

WolfgangSenff commented 4 months ago

How are you creating your documents? If you create them with a collection, and/or get them via get_doc, it should set the collection name automatically for you. If you're creating the documents manually, then it won't afaik. It's possible there's a bug there, but the whole point of having a listener feature is to have it listen to changes on the remote. The way I implemented it is a complete hack because Godot doesn't support HTTP2+ requests, but people were still needing it. It all works fine in the test harness, so if you're missing something, you might check there for how to do it (it's in the repos under the GodotNuts org).

WolfgangSenff commented 4 months ago

Wait a second. I'm wondering if I didn't test it properly! Let me double-check. That would suck. :P

WolfgangSenff commented 4 months ago

Okay, so I think it actually does work, it just takes MUCH longer than even I realized. I just tested it and was getting confused as to why it wasn't taking my timeout. It's because 2 minutes is the default. If you want to test faster, then you can change it on line 4 of the firestore_listener.gd class. That said, if you do change it to be shorter, then it is entirely ON YOU if you are charged anything for its use. Note that with updating every two seconds for an hour for only 100 users, you would be charged $40K USD. For just that hour of use. So even in testing, such short times are extremely dangerous. That is why I put a huge value on the minimum poll time - while my license largely protects me, I'd still feel bad if someone misused it and was massively charged for it. Once Godot is able to support HTTP2+ requests, I'll be able to implement actual listening without any trouble.