當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。