New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Make dataobjects index on relation changes #29
Comments
Option D pretty please |
Yeah I think Option D sounds good as well - as long as we couple it with changing documentation on methods like |
Some related (recent) discussion to Option D: silverstripe/silverstripe-framework#1923 (comment) |
Cheers for that, @kinglozzer .. 10 year old proposal! Wow. This actually does affect Based on what I'm reading in that thread, I'm thinking a combination of B and D. The reason for that is because it seems rare that all you would need is a generic hook. More than likely, you'll want access to what changed, and what the changes were. For that, we have a pretty solid API in the versioned-snapshots module for extracting that information, and we should consider moving it into core. So, that being said: Phase 1: patch
Phase 2: enhance
|
If not "move it to core", have you considered making versioned-snapshots a necessary part of this feature, and/or module? From my perspective, that would be fine. |
That's an issue if we want versioned-snapshots to be successful, since it also relies on many_many_through, right? And unlike in this case here, we identified no workarounds for this. If you want versioned snapshots to track many_many, it needs to be with many_many_through.
We'd have to think about this with Option D as well, right?
I think for these early stage modules, relying on a pre-release branch is fine. If we point out the specific patch required, you can also stay on a stable version and just pull in via composer patches. I don't believe this should influence our decision.
Not sure about that. If you use the current
Option E: Use versioned-snapshots as the source of changesI was wondering if we could "just" listen to versioned-snapshots creation events, since that already does the hard work of following ownership relationships to create a snapshot. It would also take care of the "batching" aspects, because we are triggering versioned-snapshot creation on higher level events like "save page" or "gridfield action" rather than lowlevel ORM events. We wouldn't know how the changed records were related to each other from inspecting a versioned-snapshot record, but I reckon we don't need need that. Example (with content from all items being implicitly indexed in a unified Page search index):
In all of these actions, we would identify that a Page record is involved, and trigger a reindex. This would need to happen regardless which fields are actually indexed on Page though, because it's too expensive to calculate. Which seems like an acceptable limitation? We could provide hooks to make this decisioning more granular in specific implementations. For example, if you weren't indexing the Contact, you could check only for relations you're interested in on the snapshot record (or direct changes to the Page). There's no guarantee that e.g. a Page and Tag record in the same snapshot item are actually relation through a relationship you're indexing, but I'd say it's "close enough". |
Yeah I like this idea, and I'm of the opinion that over-indexing (e.g. indexing even if nothing relevant has changed) is better than the alternative. I think one additional question to ask: |
From our projects' perspectives, we definitely need to keep the options open to a degree that Pages don't need to be indexed, e.g. using the search service just for a register of dataobjects etc. |
I think that's up to the implementation. I'd expect that most projects will simply "denormalise" blocks by rendering them out as HTML through the
https://swiftype.com/documentation/app-search/api/overview#schema-design
Yeah to my knowledge there's nothing page specific about versioned-snapshots or what we're discussing here, it's just an example. versioned-snapshots hooks into controller rather than model level events, and there's defaults for page editing through |
Currently, the reindexing hook for a dataobject comes from
onAfter(Un)Publish
, which works fine for native fields, but when relationships have changed, this hook doesn't fire because the native record is not dirty. A good example of this is associating categories to a product via aCheckboxSetField
. When the record saves, the manyMany list is updated, but the record itself is not.There are multiple paths we could take to supporting this:
Option A: Enforce "through" relationships, and add module-level smarts
In this approach, we clearly document that many_many relationships listed as indexed fields must be related via "through". We then expand the dependency tracking API to become aware of these through objects and give them a custom hook, that says, "on save, update the owner index"
Pros
Cons
add()/remove()
don't instantiate multiple indexing requests. (AFAIK dataobject saves usesetByIDList
, which is already batched implicitly)Option B: Use the versioned-snapshots RelationDiffer
We encountered the same issue in versioned snapshots, needing a new snapshot of a page when its list of owned components changed. This was solved with an agnostic service called
RelationDiffer
(source). However agnostic, it still burdens the user with calculating the list ofbefore
andafter
relation states, which is handled in versioned-snapshots fairly imperatively. Still, extracting those computations into another agnostic service seems really plausible.Pros:
Cons:
Option C: Injector sledgehammer
We overload
ManyManyList
,ManyManyThroughList
and potentiallyHasManyList
to do some indexing onadd()
remove()
andsetByIDList
, and jam these implementations into Injector.Pros:
Cons:
Option D: Patch the core and hope for a speedy merge
In this approach, we add
extend()
hooks to theRelationList
classes to fire custom hooks on add, remove, andsetByIDList
. Historically,extend()
hooks have been considered patch-level changes, and we're now doing incremental patch releases between recipe releases, which means this could become part of the core API in the very near future.Pros:
Cons:
cc @StephenMakrogianni @chillu
The text was updated successfully, but these errors were encountered: