Created
March 11, 2011 16:28
-
-
Save zdavatz/866131 to your computer and use it in GitHub Desktop.
odba - cache.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns all objects designated by _bulk_fetch_ids_ and registers | |
# _odba_caller_ for each of them. Objects which are not yet loaded are loaded | |
# from ODBA#storage. | |
def bulk_fetch(bulk_fetch_ids, odba_caller) | |
instances = [] | |
loaded_ids = [] | |
bulk_fetch_ids.each { |id| | |
if(entry = fetch_cache_entry(id)) | |
entry.odba_add_reference(odba_caller) | |
instances.push(entry.odba_object) | |
loaded_ids.push(id) | |
end | |
} | |
bulk_fetch_ids -= loaded_ids | |
unless(bulk_fetch_ids.empty?) | |
rows = ODBA.storage.bulk_restore(bulk_fetch_ids) | |
instances += bulk_restore(rows, odba_caller) | |
end | |
instances | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a = [1,2,3]
b = [3,4,5]
a -= b
p a