Created
September 8, 2021 10:43
-
-
Save davidwtbuxton/c6bbdc1e93f686cae931d1e38b5bd555 to your computer and use it in GitHub Desktop.
Python App Engine test for the Firebase Admin SDK list users API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
runtime: python38 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import firebase_admin | |
import firebase_admin.auth | |
import flask | |
import google.cloud.logging | |
google.cloud.logging.Client().setup_logging() | |
app = flask.Flask(__name__) | |
firebase_admin.initialize_app() | |
@app.route('/users1') | |
def list_users1(): | |
# Slow version, takes about 5 seconds for every 1000 users. | |
page = firebase_admin.auth.list_users() | |
count = 0 | |
for _ in page.iterate_all(): | |
count += 1 | |
if not (count % 1000): | |
logging.info('list_users1 %d', count) | |
return {'count': count} | |
@app.route('/users2') | |
def list_users2(): | |
# Fast version, takes about 1 second for every 1000 users. | |
page = firebase_admin.auth.list_users() | |
count = 0 | |
while page is not None: | |
for _ in page.users: | |
count += 1 | |
page = page.get_next_page() | |
if not (count % 1000): | |
logging.info('list_users2 %d', count) | |
return {'count': count} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
firebase-admin==5.0.2 | |
Flask==1.1.1 | |
google-cloud-logging |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment