Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
experience_builder
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
experience_builder
Merge requests
!709
Issue
#3502902
: Don't store unsaved items in autosave - alternate approach
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3502902
: Don't store unsaved items in autosave - alternate approach
issue/experience_builder-3502902:3502902-simpler
into
0.x
Overview
86
Commits
21
Pipelines
18
Changes
12
Merged
Lee Rowlands
requested to merge
issue/experience_builder-3502902:3502902-simpler
into
0.x
2 months ago
Overview
34
Commits
21
Pipelines
18
Changes
12
Expand
Closes
#3502902
0
0
Merge request reports
Compare
0.x
version 17
89821835
2 months ago
version 16
170e01b0
2 months ago
version 15
370b897f
2 months ago
version 14
5e6a99e3
2 months ago
version 13
c4092480
2 months ago
version 12
5b9e6156
2 months ago
version 11
ebebd391
2 months ago
version 10
e54b149e
2 months ago
version 9
740fcb59
2 months ago
version 8
ee59d245
2 months ago
version 7
bcac005f
2 months ago
version 6
a46830da
2 months ago
version 5
3546ece9
2 months ago
version 4
c1f5fff5
2 months ago
version 3
c09ad0d3
2 months ago
version 2
86a08751
2 months ago
version 1
e75c0a77
2 months ago
0.x (base)
and
latest version
latest version
89821835
21 commits,
2 months ago
version 17
89821835
21 commits,
2 months ago
version 16
170e01b0
20 commits,
2 months ago
version 15
370b897f
19 commits,
2 months ago
version 14
5e6a99e3
18 commits,
2 months ago
version 13
c4092480
17 commits,
2 months ago
version 12
5b9e6156
16 commits,
2 months ago
version 11
ebebd391
15 commits,
2 months ago
version 10
e54b149e
14 commits,
2 months ago
version 9
740fcb59
12 commits,
2 months ago
version 8
ee59d245
11 commits,
2 months ago
version 7
bcac005f
9 commits,
2 months ago
version 6
a46830da
8 commits,
2 months ago
version 5
3546ece9
7 commits,
2 months ago
version 4
c1f5fff5
6 commits,
2 months ago
version 3
c09ad0d3
5 commits,
2 months ago
version 2
86a08751
4 commits,
2 months ago
version 1
e75c0a77
3 commits,
2 months ago
12 files
+
559
−
30
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
12
Search (e.g. *.vue) (Ctrl+P)
src/AutoSave/AutoSaveManager.php
+
43
−
2
Options
@@ -28,13 +28,30 @@ class AutoSaveManager {
return
$this
->
tempStoreFactory
->
get
(
'experience_builder.auto_save'
,
expire
:
$expire
);
}
protected
function
getHashStore
():
AutoSaveTempStore
{
// Store for 30 days.
$expire
=
86400
*
30
;
// We need to fetch a new shared temp store from the factory for each
// usage because the current user can change in the lifetime of a request.
return
$this
->
tempStoreFactory
->
get
(
'experience_builder.auto_save.hashes'
,
expire
:
$expire
);
}
public
function
save
(
EntityInterface
$entity
,
array
$data
):
void
{
$key
=
$this
->
getAutoSaveKey
(
$entity
);
$data_hash
=
self
::
generateHash
(
$data
);
$stored_hash
=
$this
->
readHash
(
$entity
);
if
(
$stored_hash
!==
NULL
&&
\hash_equals
(
$stored_hash
,
$data_hash
))
{
// We've reset back to the original values. Clear the autosave entry but
// keep the hash.
$this
->
delete
(
$entity
,
FALSE
);
return
;
}
$auto_save_data
=
[
'entity_type'
=>
$entity
->
getEntityTypeId
(),
'entity_id'
=>
$entity
->
id
(),
'data'
=>
$data
,
'data_hash'
=>
\hash
(
'xxh64'
,
\serialize
(
$data
))
,
'data_hash'
=>
$data_hash
,
'langcode'
=>
$entity
instanceof
TranslatableInterface
?
$entity
->
language
()
->
getId
()
:
NULL
,
'label'
=>
self
::
getLabelToSave
(
$entity
,
$data
),
];
@@ -58,6 +75,15 @@ class AutoSaveManager {
return
$entity
->
getEntityTypeId
()
.
':'
.
$entity
->
id
();
}
public
function
recordInitialClientSideRepresentation
(
EntityInterface
$entity
,
array
$data
):
static
{
$this
->
getHashStore
()
->
set
(
self
::
getAutoSaveKey
(
$entity
),
self
::
generateHash
(
$data
));
return
$this
;
}
private
function
readHash
(
EntityInterface
$entity
):
?string
{
return
$this
->
getHashStore
()
->
get
(
self
::
getAutoSaveKey
(
$entity
));
}
public
function
getAutoSaveData
(
EntityInterface
$entity
):
AutoSaveData
{
$auto_save_data
=
$this
->
getTempStore
()
->
get
(
$this
->
getAutoSaveKey
(
$entity
));
if
(
\is_null
(
$auto_save_data
))
{
@@ -89,14 +115,29 @@ class AutoSaveManager {
/**
* @see \experience_builder_entity_update()
*/
public
function
delete
(
EntityInterface
$entity
):
void
{
public
function
delete
(
EntityInterface
$entity
,
bool
$resetHash
=
TRUE
):
void
{
$this
->
cacheTagsInvalidator
->
invalidateTags
([
self
::
CACHE_TAG
]);
$this
->
getTempStore
()
->
delete
(
$this
->
getAutoSaveKey
(
$entity
));
if
(
$resetHash
)
{
$this
->
getHashStore
()
->
delete
(
$this
->
getAutoSaveKey
(
$entity
));
}
}
public
function
deleteAll
():
void
{
$this
->
cacheTagsInvalidator
->
invalidateTags
([
self
::
CACHE_TAG
]);
$this
->
getTempStore
()
->
deleteAll
();
$this
->
getHashStore
()
->
deleteAll
();
}
private
static
function
generateHash
(
array
$data
):
string
{
// We use \json_encode here instead of \serialize because we're not dealing
// with PHP Objects and this ensures the representation hashed from PHP is
// consistent with the representation transmitted by the client. Some of the
// UTF characters we use in expressions are represented differently in JSON
// encoding and hence using \serialize would yield two different hashes
// depending on whether the hashing occurred before/after transfer from the
// client.
return
\hash
(
'xxh64'
,
\json_encode
(
$data
,
JSON_THROW_ON_ERROR
));
}
}
Loading