Giter Club home page Giter Club logo

Comments (5)

zrisher avatar zrisher commented on September 14, 2024

This comment from #11 is instructive:

The correct solution is to be able to derive a Contentful model completely from the cache but unfortunately it's harder than it seems to generate one from a webhook in the first place, because the Contentful library (used by ContentfulModel and ContentfulRails) can't instantiate an entry (or asset or whatever) from JSON - only from a call to the API.

Basically this is an unsolved problem.

My suggested / planned solution is probably to subclass ContentfulModel::Base and include some way of marshalling the whole thing into the cache. Then you could hook into the instrumentation call raised when a web hook arrives, hit the api, and update it. At the moment there is a recursion issue in the underlying Contentful library which needs working around before the marshalling will work.

from contentful_rails.

pxlpnk avatar pxlpnk commented on September 14, 2024

@edtjones & @zrisher there is a way that would allow to create an entry without a making an api call:
https://gist.github.com/neonichu/17a987aeeb256d4bf6f3

this is a bit hackish. I think it would make sense to open a ticket at
https://github.com/contentful/contentful.rb
and discuss this there. It would be a huge benefit to improve caching if this was possible.

from contentful_rails.

dlitvakb avatar dlitvakb commented on September 14, 2024

This has been solved for over a year. Closing.

from contentful_rails.

swetonic avatar swetonic commented on September 14, 2024

I encountered a problem recently that required me to do the Marshal.dump/Marshal.load trick. I have a content model that includes references to other pieces of content. The first time my content is put in the rails cache, it's fine. But the second time, when reading the cached entry, one of the properties is returned as a Contentful::Link instead of a Contentful::Asset.

If I do Marshal dump/load the content is a Contentful::Link always. I can then resolve the link, but of course I'd love to avoid that resolve call.

Apologies though: I just realized this may not be the place for my comment, since I'm using the Contentful API directly.

from contentful_rails.

dlitvakb avatar dlitvakb commented on September 14, 2024

Hey @swetonic,

I have identified this issue and I'm currently working on fixing it, it happens when doing Marshal.load on objects which previously had unpublished nested resources.

The inclusion errors were not serlialized, therefore the links were being displayed instead of removed from the result.

I'll be publishing a fix today on the https://github.com/contentful/contentful.rb gem.

Cheers

from contentful_rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.