当前位置: 首页>>代码示例>>Python>>正文


Python ndb.get_multi方法代码示例

本文整理汇总了Python中google.appengine.ext.ndb.get_multi方法的典型用法代码示例。如果您正苦于以下问题:Python ndb.get_multi方法的具体用法?Python ndb.get_multi怎么用?Python ndb.get_multi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.ext.ndb的用法示例。


在下文中一共展示了ndb.get_multi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GetCounterCount

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def GetCounterCount(name):
  """Sums a cumulative value from all the shard counts for the given name.

  Args:
    name: The name of the counter.

  Returns:
    Integer; the cumulative count of all sharded counters for the given
    counter name.
  """
  total = memcache.get(key=name)
  if total is not None:
    return total

  total = 0
  all_keys = CounterShardConfig.AllKeys(name)
  for counter in ndb.get_multi(all_keys):
    if counter is not None:
      total += counter.count
  if memcache.add(key=name, value=total,
                  time=_COUNTER_MEMCACHE_EXPIRATION_S):
    return total
  raise recall_errors.MessageRecallCounterError(
      'Unexpected problem adding to memcache: %s.' % name) 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:26,代码来源:sharded_counter.py

示例2: get_stats

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def get_stats(handler, resolution, now, num_items, as_dict):
  """Wrapper calls that returns items for the specified resolution.

  Arguments:
  - handler: Instance of StatisticsFramework.
  - resolution: One of 'days', 'hours' or 'minutes'
  - now: datetime.datetime or None.
  - num_items: Maximum number of items to return ending at 'now'.
  - as_dict: When True, preprocess the entities to convert them to_dict(). If
        False, returns the raw objects that needs to be handled manually.
  """
  mapping = {
    'days': _get_days_keys,
    'hours': _get_hours_keys,
    'minutes': _get_minutes_keys,
  }
  keys = mapping[resolution](handler, now, num_items)
  if as_dict:
    return [
      i.get_result() for i in _get_snapshot_as_dict_future(keys)
      if i.get_result()
    ]
  # Automatically skip missing entities.
  return [i for i in ndb.get_multi(keys) if i] 
开发者ID:luci,项目名称:luci-py,代码行数:26,代码来源:__init__.py

示例3: get_by_auth_token

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def get_by_auth_token(cls, user_id, token, subject='auth'):
      """Returns a user object based on a user ID and token.

      :param user_id:
          The user_id of the requesting user.
      :param token:
          The token string to be verified.
      :returns:
          A tuple ``(User, timestamp)``, with a user object and
          the token timestamp, or ``(None, None)`` if both were not found.
      """
      token_key = cls.token_model.get_key(user_id, subject, token)
      user_key = ndb.Key(cls, user_id)
      # Use get_multi() to save a RPC call.
      valid_token, user = ndb.get_multi([token_key, user_key])
      if valid_token and user:
          timestamp = int(time.mktime(valid_token.created.timetuple()))
          return user, timestamp

      return None, None

    # Since the original create_user method calls user.put() (where the exception occurs), only *after*
    # calling cls.unique_model.create_multi(k for k, v in uniques), this means we'll have to delete
    # those created uniques (other they'll just stay as garbage data in the DB, while not allowing
    # the user to re-register with the same username/email/etc. 
开发者ID:budowski,项目名称:rest_gae,代码行数:27,代码来源:users.py

示例4: make_reco

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def make_reco():
    """Makes the final recommendations for customers. Receives as input all
    items a given customer interacted with such as browsed items, added to 
    basket and purchased ones. Returns a list of top selected recommendations.
    """
    t0 = time.time()
    scores = base_utils.process_input_items(request.args)
    keys = map(lambda x: ndb.Key(config['recos']['kind'], x),
        scores.keys())
    entities = [e for e in ndb.get_multi(keys) if e]
    if not entities:
        result = {'results': [], 'statistics':
            {'elapsed_time': time.time() - t0}}
        return jsonify(result)
    results = utils.process_recommendations(entities, scores,
        int(request.args.get('n', 10))) 
    results['statistics'] = {}
    results['statistics']['elapsed_time'] = time.time() - t0 
    return jsonify(results) 
开发者ID:WillianFuks,项目名称:example_dataproc_twitter,代码行数:21,代码来源:main.py

示例5: AdoptProjects

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def AdoptProjects(dst_user_id, src_user_id):
  """Transfer project ownership to a new user."""

  @ndb.transactional(xg=True)
  def _AdoptProject(project_key, dst_user_key, src_user_key):
    prj, dst_user, src_user = ndb.get_multi([project_key, dst_user_key,
                                             src_user_key])
    if project_key not in src_user.projects:
      # another concurrent request and transaction beat us to it
      return
    src_user.projects.remove(project_key)
    dst_user.projects.append(project_key)
    prj.owner = dst_user_key.id()
    prj.writers.remove(src_user_key.id())
    prj.writers.append(dst_user_key.id())
    ndb.put_multi([prj, dst_user, src_user])

  src_user = GetUser(src_user_id)
  if not src_user or not src_user.projects:
    return
  dst_user = GetOrCreateUser(dst_user_id)
  for project_key in src_user.projects:
    # slow, but transactionable
    _AdoptProject(project_key, dst_user.key, src_user.key) 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:26,代码来源:model.py

示例6: GetExemptionsForHosts

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def GetExemptionsForHosts(host_keys):
  """Retrieves all Exemptions corresponding to the specified Hosts.

  Args:
    host_keys: A list of NDB Host Keys.

  Returns:
    A dictionary mapping the given Host Keys to their corresponding Exemptions,
    or None if one doesn't exist.
  """
  # Compose the expected Exemption Keys for all Hosts.
  exm_keys = [ndb.Key(flat=k.flat() + ('Exemption', '1')) for k in host_keys]

  # Grab everything from Datastore.
  exms = ndb.get_multi(exm_keys)

  # Map Host Keys to the entities we got back.
  exm_dict = {exm.key.parent(): exm for exm in exms if exm}

  # Return a mapping of all Host Keys to their Exemptions, or None for those
  # without Exemptions.
  return {host_key: exm_dict.get(host_key) for host_key in host_keys} 
开发者ID:google,项目名称:upvote,代码行数:24,代码来源:utils.py

示例7: testChangeModeForGroup_MultiBatch

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def testChangeModeForGroup_MultiBatch(self, mock_ctor):

    users = [
        test_utils.CreateUser() for _ in xrange(role_syncing.BATCH_SIZE + 1)]
    hosts = [
        test_utils.CreateSantaHost(
            primary_user=user_utils.EmailToUsername(user.key.id()),
            client_mode=MONITOR)
        for user in users]
    mock_ctor.return_value.AllMembers.return_value = [
        user.key.id() for user in users]

    response = self.testapp.get('', headers={'X-AppEngine-Cron': 'true'})

    self.assertEqual(httplib.OK, response.status_int)

    self.assertTaskCount(constants.TASK_QUEUE.DEFAULT, 2)
    self.DrainTaskQueue(constants.TASK_QUEUE.DEFAULT)

    new_hosts = ndb.get_multi(host.key for host in hosts)
    self.assertTrue(all(host.client_mode == LOCKDOWN for host in new_hosts)) 
开发者ID:google,项目名称:upvote,代码行数:23,代码来源:role_syncing_test.py

示例8: testSpiderBite

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def testSpiderBite(self):
    key_1 = test_utils.CreateSantaHost(
        client_mode=MONITOR).key
    key_2 = test_utils.CreateSantaHost(
        client_mode=MONITOR).key

    host_keys = [key_1, key_2]
    hosts = [key_1.get(), key_2.get()]

    with mock.patch.object(
        role_syncing.ndb, 'get_multi', return_value=hosts) as mock_get:
      with mock.patch.object(role_syncing.ndb, 'put_multi') as mock_put:
        role_syncing._SpiderBite(host_keys)

    self.assertEqual(1, mock_put.call_count)
    self.assertEqual(1, mock_get.call_count)
    self.assertEqual([key_1, key_2], mock_get.call_args[0][0])
    self.assertEqual([key_1.get(), key_2.get()], mock_put.call_args[0][0])
    self.assertEqual(key_1.get().client_mode, LOCKDOWN)
    self.assertEqual(key_2.get().client_mode, LOCKDOWN) 
开发者ID:google,项目名称:upvote,代码行数:22,代码来源:role_syncing_test.py

示例9: merge_user_dbs

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def merge_user_dbs(user_db, deprecated_keys):
  # TODO: Merge possible user data before handling deprecated users
  deprecated_dbs = ndb.get_multi(deprecated_keys)
  for deprecated_db in deprecated_dbs:
    deprecated_db.auth_ids = []
    deprecated_db.active = False
    deprecated_db.verified = False
    if not deprecated_db.username.startswith('_'):
      deprecated_db.username = '_%s' % deprecated_db.username
  ndb.put_multi(deprecated_dbs) 
开发者ID:lipis,项目名称:github-stats,代码行数:12,代码来源:user.py

示例10: get

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def get(self):
    user_keys = util.param('user_keys', list)
    if user_keys:
      user_db_keys = [ndb.Key(urlsafe=k) for k in user_keys]
      user_dbs = ndb.get_multi(user_db_keys)
      return helpers.make_response(user_dbs, model.User.FIELDS)

    user_dbs, cursors = model.User.get_dbs(prev_cursor=True)
    return helpers.make_response(user_dbs, model.User.FIELDS, cursors) 
开发者ID:lipis,项目名称:github-stats,代码行数:11,代码来源:user.py

示例11: get

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def get(self):
    repo_keys = util.param('repo_keys', list)
    if repo_keys:
      repo_db_keys = [ndb.Key(urlsafe=k) for k in repo_keys]
      repo_dbs = ndb.get_multi(repo_db_keys)
      return helpers.make_response(repo_dbs, model.repo.FIELDS)

    repo_dbs, repo_cursor = model.Repo.get_dbs()
    return helpers.make_response(repo_dbs, model.Repo.FIELDS, repo_cursor) 
开发者ID:lipis,项目名称:github-stats,代码行数:11,代码来源:repo.py

示例12: get

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def get(self):
    account_keys = util.param('account_keys', list)
    if account_keys:
      account_db_keys = [ndb.Key(urlsafe=k) for k in account_keys]
      account_dbs = ndb.get_multi(account_db_keys)
      return helpers.make_response(account_dbs, model.account.FIELDS)

    account_dbs, account_cursor = model.Account.get_dbs()
    return helpers.make_response(account_dbs, model.Account.FIELDS, account_cursor) 
开发者ID:lipis,项目名称:github-stats,代码行数:11,代码来源:account.py

示例13: forProject

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def forProject(cls, project_name):
        """Returns the alerts created for supplied project."""
        alert_keys = []
        alert_keys = Alert.query(
            Alert.project == project_name,
            ancestor=Alert.entity_group).fetch(keys_only=True)
        alerts = ndb.get_multi(alert_keys)
        return alerts 
开发者ID:googlearchive,项目名称:billing-export-python,代码行数:10,代码来源:main.py

示例14: get_keyword

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def get_keyword():
    data = memcache.get(key="keyword")
    if data is None:
        q = KeyWord.query()
        data = ndb.get_multi(q.fetch(keys_only=True))
        memcache.add(key="keyword", value=data, time=86400 * 30)
    return data 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:9,代码来源:models.py

示例15: get_enable_keyword

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_multi [as 别名]
def get_enable_keyword():
    data = memcache.get(key="enable_keyword")
    if data is None:
        q = KeyWord.query(KeyWord.enable == True)
        data = ndb.get_multi(q.fetch(keys_only=True))
        memcache.add(key="enable_keyword", value=data, time=86400 * 30)
    return data 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:9,代码来源:models.py


注:本文中的google.appengine.ext.ndb.get_multi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。