Skip to content

Instantly share code, notes, and snippets.

@zdavatz
Created March 11, 2011 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdavatz/866131 to your computer and use it in GitHub Desktop.
Save zdavatz/866131 to your computer and use it in GitHub Desktop.
odba - cache.rb
# 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
@mhatakeyama
Copy link

a = [1,2,3]
b = [3,4,5]

a -= b

p a

@zdavatz
Copy link
Author

zdavatz commented Mar 14, 2011

this will result in [1,2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment