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
Too many versions per save action #166
Comments
This issue seems to manifest itself more seriously (read: worsens) in of course the modified files are now Publish.
|
Initial discovery by @robbieaverill at silverstripe/cwp#118 |
I just gave a go at replicating this and did manage to do it. I tried with a Dummy DataObject and a SiteTree object and got the same result If I edit an object and save it a get one new entry in my version table. If I publish my draft version, I get one new entry in my version table. If I edit an object and publish it without saving it first, I get two new versions. Do you have any ownership relations between your objects? |
Nope. No changes to code were made between first test ( |
I'm pretty sure this has been reported before and @tractorcow said it was intended |
This was the issue I was thinking about: #136 maybe not an exact duplicate, but sounds similar enough. |
We have a known limitation where we have to do an initial write (draft only version), and THEN send the whole object into a publish changeset, where it creates a second version (draft + live) alongside all other objects in that changeset. What we could do to fix this is allow unsaved items to be added to changesets. That way It'll require a bit of magic, since a changeset / changesetitem instance will need to be passed through the publishing lifecycle. You may need to assign a kind of "temp" relation on changeset that holds all the unpublished records being written in this transaction, maybe with a temp ID? (non-numeric id like |
Sorry that may not address the "three versions" created issue, but it does combine at least two of them into one. The third is just a dumb logic in gridfield somewhere, probably. |
The new logic in 4.2 is the deleted version tracking and draft/published state of each version. |
My 2c worth is that I can also confirm the same behaviour on
|
I see something interesting if I decorate both |
@phptek this is because File (and thus Image) already has |
@NightJar Yeah, I'm torn between "It shouldn't be allowed" (Throw an exception if someone tries to do this) and "Let them shoot themselves in the foot ala "rm -rf /".
Fairly sure...if I get the chance I'll update, but if this isn't supposed to happen as you describe, then it's kinda moot. |
We really need to address this when implementing version snapshots as described in #195 soon - every save and publish operation will become a lot more expensive this way. |
I can't reproduce this on So the system seems to work as designed now? Can anyone clarify why we are creating two versions on a publish with unsaved changes, one for draft, immediately followed by a live one? We can't call On create:
On first save and publish:
I now understand what @tractorcow comment refers to with "unsaved objects". They exist in the database, but have unsaved changes. Without this first draft version write, it would be "unsaved" at the point when I don't think it needs a "temp ID" as suggested by @tractorcow. Records are always saved (through My suggestion is that we create This might also be solved by an identity map as suggested in the eager loading RFC, if we create this map independently from relationships - I don't think that's the case yet, and probably a larger effort. It would also require that this single in-memory object would carry through unsaved changes which aren't persisted in the database yet, which might get horribly confusing. Env info:
|
No feedback, closing |
Minimum steps to reproduce
composer create-project silverstripe/recipe-cms test ^4
app/src/AnThing.php
app/src/Page.php
Build site.
Load CMS.
Edit Home.
The Things tab
Add An Thing
Enter a Title
Create
-> Database shows one version. ✅ (new record, first version)
Change title.
Publish.
-> Database shows three versions. ✅ (two versions created for two actions {save, publish})
Alter title.
Save.
-> Database shows five versions ❌ (two versions created for one action {save})
Alter title.
Publish.
-> Database shows seven versions ✅ (two versions created for two actions {save, publish})
Alter title.
Save.
-> Database shows nine versions ❌ (two versions created for one action {save})
do not alter title.
Save.
-> Database shows ten versions ✅ (one new version for one action {publish})
The text was updated successfully, but these errors were encountered: