Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Created September 8, 2021 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwtbuxton/c6bbdc1e93f686cae931d1e38b5bd555 to your computer and use it in GitHub Desktop.
Save davidwtbuxton/c6bbdc1e93f686cae931d1e38b5bd555 to your computer and use it in GitHub Desktop.
Python App Engine test for the Firebase Admin SDK list users API
runtime: python38
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}
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