Guest User

Untitled

a guest
Jul 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. @staticmethod
  2. def fetch(sgids):
  3. # Create a unique list.
  4. sgids = list(set(sgids))
  5.  
  6. keys = map(lambda x: "Record.%s" % x, sgids)
  7. cached = cache.get_multi(keys)
  8.  
  9. found = map(lambda x: cached[x]['sgid'], cached)
  10.  
  11. diff = list(set(sgids) - set(found))
  12.  
  13. parent = ColumnParent(column_family=Record.Meta.column_family)
  14. predicate = SlicePredicate(slice_range=SliceRange(start="",
  15. finish=""))
  16.  
  17. cass = False
  18. if len(diff):
  19. res = get_pool(Record.Meta.keyspace).multiget_slice(
  20. Record.Meta.keyspace, diff, parent, predicate,
  21. ConsistencyLevel.ONE)
  22.  
  23. cass = dict([(key, dict([(col.column.name, col.column.value) for
  24. col in cols])) for key, cols in res.iteritems()])
  25.  
  26. cached.update(cass)
  27.  
  28. ret = {}
  29. for key, rec in cached.iteritems():
  30. ret[rec['sgid']] = Record(**rec)
  31. if cass and key in cass:
  32. ret[key].cache()
  33.  
  34. return ret
Add Comment
Please, Sign In to add comment