ruby-rdf / rdf-vocab

Common RDF Vocabularies
The Unlicense
50 stars 29 forks source link

require the exact path to vocabularies #51

Closed dunn closed 6 years ago

dunn commented 6 years ago

Due to quirks in Rails' autoloading behavior, currently some vocabularies can fail to be loaded, leading to curious situations like this:

irb(main):007:0> RDF::Vocab.constants
=> [:ICAL, :Identifiers, :IIIF, :JSONLD, :LRMI, :MA, :MADS, :MARCRelators, :MO, :MODS, :NFO, :GS1, :HT, :OG, :LDP, :ORE, :OGC, :OA, :ORG, :PPLAN, :PREMIS, :PremisEventType, :PROV, :PTR, :RightsStatements, :RSS, :SCHEMA, :SIOC, :SiocServices, :SKOS, :SKOSXL, :V, :VMD, :VCARD, :VOID, :VS, :WDRS, :WOT, :XKOS, :XHTML, :XHV, :VERSION, :VOCABS, :ACL, :BF2, :Bibframe, :CNT, :BIBO, :CC, :CERT, :CRM, :DataCite, :DC, :DC11, :DCMIType, :DISCO, :RSA, :DWC, :EBUCore, :DCAT, :EDM, :EXIF, :DOAP, :FOAF, :Fcrepo4, :GEOJSON, :GEO, :GR, :GEONAMES, :HYDRA, :IANA]
irb(main):008:0> RDF::Vocab::GEONAMES
NameError: uninitialized constant RDF::Vocab::GEONAMES
        from (irb):8
gkellogg commented 6 years ago

This is too heavy handed, loading every vocabulary in spite of use will use a massive amount of memory. I'm fine with using absolute paths to the libraries, but not changing autoload to require.

It does seem that Rails creates an autoload race condition (see https://stackoverflow.com/questions/29439323/rails-4-2-autoloading-not-thread-safe).

Some alternatives would be to create a load_all class module method which would do the require, and could be done early in Rails configuration, or to simply whitelist the vocabularies you rely on and cause them to autoload on initialization.

A note in the README about this issue, and hopeful resolution, would be useful.

dunn commented 6 years ago

Interestingly, passing the full path to autoload also seems to work. PR updated.

gkellogg commented 6 years ago

I’ll release soon.