Coder Social home page Coder Social logo

Comments (15)

pyromaniac avatar pyromaniac commented on August 17, 2024

Yeah, currently there is no way to do it. Indexing objects with parent is not supported for now. I need to dig deeper to figure out how to do this.

Currently I think it should be like this:

define_type Column.includes(:table) do
  root _parent: { type: 'table' }, parent: -> { table.id } do
    field ...
  end
end

Or maybe use parent_id key instead of just parent to define parent id evaluator proc

from chewy.

jondavidford avatar jondavidford commented on August 17, 2024

Okay, I may work on this but for now it'd be nice to have a work-around for my use case. Basically there is a field in the parent that is expensive to calculate and is also needed for each of its children. If I could store results for this expensive function in a hash at index time then I could just look up in the hash instead of having to recalculate for each child.

I tried doing something like this but just getting Nil for the @table_permissions_store.

@table_permissions_store = TablePermissionsStore.new()

define_type Table do
  field :_id, type: 'integer', value: { id }
  field :user_ids, value: -> { @table_permissions_store.get_permission(self) }
end

define_type Column.includes(:table) do
  field :user_ids, value: -> { @table_permissions_store.get_permission(table) }
end

Is there any way to do something like this?

from chewy.

pyromaniac avatar pyromaniac commented on August 17, 2024

Yeah, sure, because value procs are called in the AR object context. Try value: -> (table) { @table_permissions_store.get_permission(table) } At this case the context of value proc should not be changed. But I'm still not sure you need this. It seems like TablePermissionsStore object will be initialized only once on the application start. If this is what you need - it is better to use constant, it will be available from every context. If this is not - then explain what are you trying to do. Maybe it is a new object for every stored record?

from chewy.

jondavidford avatar jondavidford commented on August 17, 2024

Sorry, it is just a hash that stores permissions at index time. If the key for a specific table is already in the hash then it just does a lookup and the value at that key is the permission. If the key isn't there then it runs the expensive function to get the user permissions and stores it in the hash.

So anytime a new index action is occurring (specifically reset and import), the hash should be reset to be empty (since permissions can change). Maybe I can use the chewy atomic block?

from chewy.

pyromaniac avatar pyromaniac commented on August 17, 2024

I'm still thinking about how to implement such a case. Previous code will not work, I'm sure. But Don't even know. Maybe you have to redefine import method for index? To initialize TablePermissionsStore, but how to access it inside importer? Maybe use a kind of https://github.com/pyromaniac/contextuality to create variable inside the import context. Not sure.

from chewy.

jondavidford avatar jondavidford commented on August 17, 2024

Okay, it seems like a work around will be pretty difficult so I'm just going to work on adding in parent/child mappings.

from chewy.

baothi avatar baothi commented on August 17, 2024

https://gist.github.com/baothi/72c63fbb9b8b4675188e
please help me error

from chewy.

pyromaniac avatar pyromaniac commented on August 17, 2024

just place tcos_index.rb inside app/chewy dir and pay attention to it's name

from chewy.

baothi avatar baothi commented on August 17, 2024

hi pyromaniac
yes I do same gem chewy but It until error

from chewy.

pyromaniac avatar pyromaniac commented on August 17, 2024

are you sure your file named tacos_index.rb?

from chewy.

baothi avatar baothi commented on August 17, 2024

https://www.youtube.com/watch?v=v_MCcue2uEA
yes i see here

from chewy.

baothi avatar baothi commented on August 17, 2024

hi pyromaniac
have you skype, you can add my skype help me
my skype: bao.thi2

from chewy.

pyromaniac avatar pyromaniac commented on August 17, 2024

just try to execute spring stop in bash and do rails c once again

from chewy.

baothi avatar baothi commented on August 17, 2024

hi pyromaniac
yes i try ``spring stop` but it still error

from chewy.

baothi avatar baothi commented on August 17, 2024

hi pyromaniac
when i do again bin/spring stop it run TacosIndex but when i run TacosIndex::Taco.import(Taco.all)
it error Faraday::ConnectionFailed: Connection refused - connect(2) for "localhost" port 9200

from chewy.

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.