firebase / firebase/firebase-cpp-sdk

[FR] Database (Desktop): Add support for special server value Increment

Offen
#649 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
api: database type: feature request
Vorherrschende Sprache
C++
Sterne
326
Forks
137
Ø Merge
3 T. 9 Std.
Gemergte PRs (30 T.)
5

Beschreibung

### Feature proposal

* Firebase Component: Database

As of last year, Realtime Database [supports a special value for incrementing locations in the database atomically without running a transaction](https://firebase.google.com/support/release-notes/js#version_7140_-_april_9_2020), but this feature is not exposed in the C++ (or Unity) implementations.

This is accomplished in Java by assigning a value in the database to `ServerValue.increment()`. This is similar to how timestamps work, with `ServerValue.timestamp()`. Both functions return a special value that is treated specially on the server and client.

In C++ we have a [ServerTimestamp()](
https://github.com/firebase/firebase-cpp-sdk/blob/3c2190901976a218cd4dc91b0e6aae5afc8d9291/database/src/include/firebase/database/common.h#L78) function that returns that special value. We should add a new function, something like `ServerValueIncrement()` or something similar, which generates the special value for the developer. IIRC the special value is just a map containing `{".sv":"increment"}` or something similar.

This special value would then get special handling in [server_values.cc](https://github.com/firebase/firebase-cpp-sdk/blob/main/database/src/desktop/core/server_values.cc) so that the operation can be approximated locally while the data makes its server round trip.

[Here is the Java implementation of the server value](https://github.com/firebase/firebase-android-sdk/blob/67f91adb82f3ccf5e94a6c44beef7188f83ec324/firebase-database/src/main/java/com/google/firebase/database/core/ServerValues.java#L32) code. This logic can probably be duplicated in C++ without much trouble. Pay attention in particular to [resolveComplextDeferredValue()](https://github.com/firebase/firebase-android-sdk/blob/67f91adb82f3ccf5e94a6c44beef7188f83ec324/firebase-database/src/main/java/com/google/firebase/database/core/ServerValues.java#L70)

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start with database/src/include/firebase/database/common.h and its ServerTimestamp() entry point, then read database/src/desktop/core/server_values.cc and the linked Java ServerValues implementation. Add the public increment server value and local handling for the special value, including the server round-trip approximation described in the issue; done means C++ and Unity users can use atomic increments consistently.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
cpp, firebase
Bereich
databases
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.