| OLD | NEW |
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides info about projects (service tenants).""" | 5 """Provides info about projects (service tenants).""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 from google.appengine.api import memcache | 9 from google.appengine.api import memcache |
| 10 from google.appengine.ext import ndb | 10 from google.appengine.ext import ndb |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 pid: ctx.memcache_get(pid, namespace=cache_ns) | 108 pid: ctx.memcache_get(pid, namespace=cache_ns) |
| 109 for pid in project_ids | 109 for pid in project_ids |
| 110 } | 110 } |
| 111 yield cache_futs.values() | 111 yield cache_futs.values() |
| 112 result = {} | 112 result = {} |
| 113 missing = [] | 113 missing = [] |
| 114 for pid in project_ids: | 114 for pid in project_ids: |
| 115 binary = cache_futs[pid].get_result() | 115 binary = cache_futs[pid].get_result() |
| 116 if binary is not None: | 116 if binary is not None: |
| 117 # cache hit | 117 # cache hit |
| 118 if binary is PROJECT_DOES_NOT_EXIST_SENTINEL: | 118 if binary == PROJECT_DOES_NOT_EXIST_SENTINEL: |
| 119 result[pid] = None | 119 result[pid] = None |
| 120 else: | 120 else: |
| 121 cfg = project_config_pb2.ProjectCfg() | 121 cfg = project_config_pb2.ProjectCfg() |
| 122 cfg.ParseFromString(binary) | 122 cfg.ParseFromString(binary) |
| 123 result[pid] = cfg | 123 result[pid] = cfg |
| 124 else: | 124 else: |
| 125 # cache miss | 125 # cache miss |
| 126 missing.append(pid) | 126 missing.append(pid) |
| 127 | 127 |
| 128 if missing: | 128 if missing: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 # TODO(nodir): optimize | 188 # TODO(nodir): optimize |
| 189 assert isinstance(project_ids, list) | 189 assert isinstance(project_ids, list) |
| 190 if not project_ids: | 190 if not project_ids: |
| 191 return project_ids | 191 return project_ids |
| 192 assert all(pid for pid in project_ids) | 192 assert all(pid for pid in project_ids) |
| 193 all_project_ids = set(p.id for p in get_projects()) | 193 all_project_ids = set(p.id for p in get_projects()) |
| 194 return [ | 194 return [ |
| 195 pid for pid in project_ids | 195 pid for pid in project_ids |
| 196 if pid in all_project_ids | 196 if pid in all_project_ids |
| 197 ] | 197 ] |
| OLD | NEW |