google-app-engine


Appengine ndb - How to ensure unique username and email without ancestors?


In my Appengine (using ndb) application I store users and both username and email need to be unique.
I also need to be able to update progress (save level if higher than previously stored level), change email and pw and delete account.
I noticed that it is not possible to query without ancestors in a transaction. But creating an ancestor is NOT a solution since that would limit the number of writes to 1 per second which is not OK if the app gets popular. So I need another solution.
Is it possible to use the Key? Yes, but that only makes the username unique, how can I make sure noone is reusing the email for another account?
You should be able to use a cross group transaction for this along with an entity that exists solely for reserving email addresses.
For your User entity, you could use the username as the key name. When creating a user, you also create an EmailReservation entity that has the user's email address as a key name.
You then use a cross-group transaction to create a new user:
#ndb.transactional(xg=True)
def create_user(user_name, email):
user = User.get_by_id(user_name)
email_reservation = EmailReservation.get_by_id(email)
if user or email_reservation:
# Either the user_name or email is already in use so stop
return None
# Create the user and reserve the email address so others can't use it
user = User(id=user_name)
email_reservation = EmailReservation(id=email)
ndb.put_multi(user, email_reservation)
return user

Related Links

Trouble locating static audio file on Google App Engine
Final GAE vs AWS architectural decision
how to read ZipInputStream into CharArrayReader
Google app engine: personal experiences?
Uploading multiple files to blobstore (redux)
App Engine: Can I upload my local dev_appserver.datastore to the live datastore?
App Engine URL mapping
Sitemaps structure for large App Engine site
cheetah in appengine
Help to Upload zip file containing CSV file in GAE
Google App Engine: Using datastore with users who are not logged in
Text to HTML converter for Google App Engine
Pagination and Multiple relational entity indexes with AppEngine
time taken to upload a picture of 1M ~ 5M from iPhone to either Google AE or Amazon S3
Sending email from dev server with --smtp_host=smtp.gmail.com
Google App Engine logout url

Categories

HOME
windows
azure-stream-analytics
string
forms
fpga
rsa
ms-access-2016
bitbucket-api
switch-statement
rds
echo
banner
barcode
g++
pcl-crypto
ipmitool
jsonpath
php-5.6
nancy
internationalization
feathersjs
forgot-password
enterprise-miner
dpdk
angular-routing
exploit
monit
pic32
corenlp-server
userdefaults
livelink
simplecv
installshield-le
joomla2.5
yowsup
magento-1.9.2.4
lint
openalpr
bc
loading
typesafe-config
tasm
trigonometry
datacachefactory
preloader
claims
outputcache
avcapturedevice
clang++
memory-mapping
openresty
wcftestclient
convex-optimization
carrot2
tinkerpop
filehandle
google-photos
cd-burning
rxtx
structuremap4
rsa-archer-grc
vcloud-director-rest-api
omxplayer
drawstring
respondcms
kiosk
blitline
phpgrid
maybe
directdraw
iokit
roadkill-wiki
microsoft-reporting
rpart
sql-server-data-tools
entity-framework-4.3
gamekit
code-documentation
rapidsvn
genymotion-call
paw
mobility
mintty
matrix-inverse
jjaql
dct
fpdi
away3d
jeromq
inappsettingskit
kogrid
gpars
time.h
wp7test
device-width
curb
subproject
oracle-enterprise-linux
android-holo-everywhere
u2netdk
listactivity
resharper-6.0
maven-1
cuda.net
httpcookie

Resources

Encrypt Message