Skip to content
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

Save compaction #2966

Merged
merged 9 commits into from
Jun 21, 2022
Merged

Save compaction #2966

merged 9 commits into from
Jun 21, 2022

Conversation

Macroz
Copy link
Collaborator

@Macroz Macroz commented Jun 17, 2022

Implements consecutive save compaction for #2767

Checklist for author

Remove items that aren't applicable, check items that are done.

Reviewability

  • Link to issue

Backwards compatibility

  • API is backwards compatible or completely new
  • Events are backwards compatible

Documentation

  • Update changelog if necessary
  • ADR for major architectural decisions or experiments (ADR 17)

Testing

  • Complex logic is unit tested
  • Valuable features are integration / browser / acceptance tested automatically

Follow-up

Improvements to the test, so that we can implement compaction without
breaking the assumptions.

- Check differently that event ids are increasing, so that there
  doesn't need to be the same amount of events, which will not work
  with compaction.
- Write a different field value each time, but don't do it with the
  redef. Previously the "app version" was the same as the number of
  events. With compaction that will not be true, so we'll add a
  separate (sequential) number to check that the last one wins.
- The number of final events is going to be different after
  compaction.
- Event ids will have gaps after compaction is enabled, so we can't
  enforce that.
If the event is a draft save, and the last event was a draft save too,
we'll replace the last event with the new data, and new id,
effectively deleting the old one. This will leave gaps in the event
ids, but saves space after autosave is added.
The event ids are generated in the database after the command has
processed the results. We can update the events in the result to
return the latest info.
Added the historical decision and the other issue result.
@Macroz Macroz marked this pull request as ready for review June 18, 2022 08:25
Let's keep the feature as optional until the rest of the autosave is ready.
The description of `:dev` doesn't make sense as the really
experimental features have their own flags. And most of the feature
are not experimental.
Copy link
Collaborator

@aatkin aatkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice! i had not anticipated the extra work in transaction testing, but you got that covered 👍

Comment on lines +89 to +90
(= (:application/id event)
(:application/id last-event)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we omit this check, i think application id should always be the same?

(= (:application/id event)
   (:application/id last-event))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I look like it, yes we could. I added the condition because it didn't seem to work otherwise, but with a closer inspection it mostly should have and it was probably something else. Technically there can be n events returned from a single command, and they could affect different applications (like "copy as new" does), but here, we are considering the save which never does it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll leave the check here as it is cheap. So it's kind of regression protection if we choose to create more complex commands or use the function from elsewhere.

I don't want to fetch the application of each event here with get-application-internal as that is not so cheap (it fetches the events and rebuilds the view).


Returns the event as it went into the db."
[event]
(let [old-event (fix-event-from-db (first (db/get-application-event {:id (:event/id event)})))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the existing SQL function has a little silly return, considering the name indicates it should return single event but it returns a list of events. maybe that could be refactored at some point :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think the correct naming convention that we use elsewhere is :get-application-events (which does exist too). There could be a db function named :get-application-event but it should have been declared like get-latest-application-event i.e. :1. This is a bit of leftover from my refactoring of combining together some previous functions, but choosing the wrong name / not finishing all the changes. "search" functions should accept many parameters and return 0..n and singular "get" functions should always return 0..1.

Copy link
Collaborator Author

@Macroz Macroz Jun 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Macroz Macroz merged commit 51b6b39 into master Jun 21, 2022
@Macroz Macroz deleted the save-compaction branch June 21, 2022 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants