def post(self): """This post is for priming/prefetching, not actually delivering the widget """ start = time.time() api_key = self.request.get('apikey') account_id = self.request.get('accountid') user_id = self.request.get('userid') widget_type = self.request.get('widget') logdiction = {'event':'prefetchwidget', 'api':'get_widget', 'user':user_id, 'is_api':'yes', 'ip':self.request.remote_addr, 'account':account_id, 'widget':widget_type, 'success':'true'} if widget_type not in constants.VALID_WIDGETS: logdiction['success'] = 'false' logdiction['details'] = "Using an invalid widget name" logs.create(logdiction) self.response.out.write(bad_args()) return # Get the account acc_ref = accounts_dao.authorize_api(account_id, api_key) if not acc_ref: logdiction['success'] = 'false' logdiction['details'] = auth_error() logs.create(logdiction) self.response.out.write(auth_error()) return if not user_id and widget_type in constants.WIDGETS_THAT_DONT_NEED_A_USER: user_id = constants.ANONYMOUS_USER if not user_id: logdiction['success'] = 'false' logdiction['details'] = bad_args() logs.create(logdiction) self.response.out.write(bad_args()) return user_ref = None if user_id: user_ref = users_dao.get_user_with_key(user_id) if not user_ref and user_id == constants.ANONYMOUS_USER: users_dao.create_new_user(account_id, constants.ANONYMOUS_USER) #acc_ref = users_dao.get_account_from_user(user_ref) # TODO Need to measure if there is an actual gain from this prefetching # or if it's causing unnecessary contention values = getattr(self, widget_type + "_values")(user_ref, acc_ref, 500, 300) logs.create(logdiction) return
def get(self): """ Generate several accounts and users to test out stuff with """ for i in range(10): """ create 10 accounts """ email = "user" + str(i) + "@infuser.com" account_entity = accounts_dao.create_account(email, "1111", True) for j in range(random.randint(40,100)): """ create 40-100 users per account """ user_id = "crazy" + str(i) + "crazy" + str(j) + "@someplaceelse" + str(i) + ".com" users_dao.create_new_user(email, user_id) users_dao.set_user_points(email, user_id, random.randint(5,200)) self.response.out.write("Done. :-)")
def get(self): """ Generate several accounts and users to test out stuff with """ for i in range(10): """ create 10 accounts """ email = "user" + str(i) + "@infuser.com" account_entity = accounts_dao.create_account(email, "1111", True) for j in range(random.randint(40, 100)): """ create 40-100 users per account """ user_id = "crazy" + str(i) + "crazy" + str( j) + "@someplaceelse" + str(i) + ".com" users_dao.create_new_user(email, user_id) users_dao.set_user_points(email, user_id, random.randint(5, 200)) self.response.out.write("Done. :-)")
def create_account(email, password, enable=False, account_type="bronze", payment_type="free"): """ Creates an account with all the other needed dependencies properly initialized. """ """ Required: email = db.EmailProperty(required=True) password = db.StringProperty(required=True); isEnabled = db.StringProperty(required=True, choices=ACCOUNT_STATUS.RANGE_OF_VALUES) accountType = db.StringProperty(required=True, choices=set(ACCOUNT_TYPES)) paymentType = db.StringProperty(required=True,choices=set(PAYMENT_TYPES)) cookieKey = db.StringProperty(required=True) apiKey = db.StringProperty(required=True) trophyWidget = db.ReferenceProperty(required=True, reference_class=TrophyCase) pointsWidget = db.ReferenceProperty(required=True, reference_class=Points) rankWidget = db.ReferenceProperty(required=True, reference_class=Rank) """ new_trophy_case = TrophyCase(key_name=email) memcache_db.save_entity(new_trophy_case, email) new_rank = Rank(key_name=email) memcache_db.save_entity(new_rank, email) new_points = Points(key_name=email) memcache_db.save_entity(new_points, email) new_notifier = Notifier(key_name=email) memcache_db.save_entity(new_notifier, email) new_leader = Leaderboard(key_name=email) memcache_db.save_entity(new_leader, email) new_milestones = Milestones(key_name=email) memcache_db.save_entity(new_milestones, email) """ Generate an API key """ api_key = str(uuid.uuid4()) """ Hash the password """ hashed_password = hashlib.sha1(password).hexdigest() enable_account = ACCOUNT_STATUS.PENDING_CREATE if enable: enable_account = ACCOUNT_STATUS.ENABLED newacc = Accounts(key_name=email, email=email, password=hashed_password, isEnabled=enable_account, accountType=account_type, paymentType=payment_type, apiKey=api_key, cookieKey="xxxxxxxxxxxxxx", trophyWidget=new_trophy_case, pointsWidget=new_points, rankWidget=new_rank, notifierWidget=new_notifier, leaderWidget=new_leader, milestoneWidget=new_milestones) try: memcache_db.save_entity(newacc, email) except: logging.error("Failed to create account") users_dao.create_new_user(email, constants.ANONYMOUS_USER) return newacc
def create_account(email, password, enable=False, account_type="bronze", payment_type="free"): """ Creates an account with all the other needed dependencies properly initialized. """ """ Required: email = db.EmailProperty(required=True) password = db.StringProperty(required=True); isEnabled = db.StringProperty(required=True, choices=ACCOUNT_STATUS.RANGE_OF_VALUES) accountType = db.StringProperty(required=True, choices=set(ACCOUNT_TYPES)) paymentType = db.StringProperty(required=True,choices=set(PAYMENT_TYPES)) cookieKey = db.StringProperty(required=True) apiKey = db.StringProperty(required=True) trophyWidget = db.ReferenceProperty(required=True, reference_class=TrophyCase) pointsWidget = db.ReferenceProperty(required=True, reference_class=Points) rankWidget = db.ReferenceProperty(required=True, reference_class=Rank) """ new_trophy_case = TrophyCase(key_name=email) memcache_db.save_entity(new_trophy_case, email) new_rank = Rank(key_name=email) memcache_db.save_entity(new_rank, email) new_points = Points(key_name=email) memcache_db.save_entity(new_points, email) new_notifier = Notifier(key_name=email) memcache_db.save_entity(new_notifier, email) new_leader = Leaderboard(key_name=email) memcache_db.save_entity(new_leader, email) new_milestones = Milestones(key_name=email) memcache_db.save_entity(new_milestones, email) """ Generate an API key """ api_key = str(uuid.uuid4()) """ Hash the password """ hashed_password = hashlib.sha1(password).hexdigest() enable_account = ACCOUNT_STATUS.PENDING_CREATE if enable: enable_account = ACCOUNT_STATUS.ENABLED newacc = Accounts(key_name = email, email = email, password = hashed_password, isEnabled = enable_account, accountType = account_type, paymentType = payment_type, apiKey = api_key, cookieKey = "xxxxxxxxxxxxxx", trophyWidget = new_trophy_case, pointsWidget = new_points, rankWidget = new_rank, notifierWidget = new_notifier, leaderWidget = new_leader, milestoneWidget = new_milestones) try: memcache_db.save_entity(newacc, email) except: logging.error("Failed to create account") users_dao.create_new_user(email, constants.ANONYMOUS_USER) return newacc