mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
GO-1227 allow to explicitly set lastModifiedDate for the first change
This commit is contained in:
parent
5ee701bf26
commit
a61d1264d8
7 changed files with 30 additions and 4 deletions
|
@ -631,12 +631,23 @@ func (sb *smartBlock) Apply(s *state.State, flags ...ApplyFlag) (err error) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
var lastModified = time.Now()
|
||||
if s.ParentState() != nil && s.ParentState().IsTheHeaderChange() {
|
||||
// in case it is the first change, allow to explicitly set the last modified time
|
||||
// this case is used when we import existing data from other sources and want to preserve the original dates
|
||||
if err != nil {
|
||||
log.Errorf("failed to get creation info: %s", err)
|
||||
} else {
|
||||
lastModified = time.Unix(pbtypes.GetInt64(s.LocalDetails(), bundle.RelationKeyLastModifiedDate.String()), 0)
|
||||
}
|
||||
}
|
||||
if err = sb.onApply(s); err != nil {
|
||||
return
|
||||
}
|
||||
if sb.Anytype() != nil {
|
||||
// this one will be reverted in case we don't have any actual change being made
|
||||
s.SetLastModified(time.Now().Unix(), sb.Anytype().PredefinedBlocks().Profile)
|
||||
s.SetLastModified(lastModified.Unix(), sb.Anytype().PredefinedBlocks().Profile)
|
||||
}
|
||||
beforeApplyStateTime := time.Now()
|
||||
|
||||
|
@ -671,6 +682,7 @@ func (sb *smartBlock) Apply(s *state.State, flags ...ApplyFlag) (err error) {
|
|||
}
|
||||
}
|
||||
pushChangeParams := source.PushChangeParams{
|
||||
Time: lastModified,
|
||||
State: st,
|
||||
Changes: changes,
|
||||
FileChangedHashes: getChangedFileHashes(s, fileDetailsKeysFiltered, act),
|
||||
|
|
|
@ -1378,6 +1378,12 @@ func (s *State) ParentState() *State {
|
|||
return s.parent
|
||||
}
|
||||
|
||||
// IsTheHeaderChange return true if the state is the initial header change
|
||||
// header change is the empty change without any blocks or details except protocol data
|
||||
func (s *State) IsTheHeaderChange() bool {
|
||||
return s.changeId == s.rootId
|
||||
}
|
||||
|
||||
func (s *State) RemoveDetail(keys ...string) (ok bool) {
|
||||
det := pbtypes.CopyStruct(s.Details())
|
||||
if det != nil && det.Fields != nil {
|
||||
|
|
|
@ -99,7 +99,8 @@ func (oc *ObjectCreator) Create(ctx *session.Context,
|
|||
|
||||
st := state.NewDocFromSnapshot(newID, sn.Snapshot).(*state.State)
|
||||
st.SetRootId(newID)
|
||||
|
||||
// explicitly set last modified date, because all local details removed in NewDocFromSnapshot; createdDate covered in the object header
|
||||
st.SetLastModified(pbtypes.GetInt64(sn.Snapshot.Data.Details, bundle.RelationKeyLastModifiedDate.String()), oc.core.ProfileID())
|
||||
defer func() {
|
||||
// delete file in ipfs if there is error after creation
|
||||
oc.onFinish(err, st, filesToDelete)
|
||||
|
@ -195,6 +196,7 @@ func (oc *ObjectCreator) setFavorite(snapshot *model.SmartBlockSnapshotBase, new
|
|||
func (oc *ObjectCreator) setWorkspaceID(err error, newID string, snapshot *model.SmartBlockSnapshotBase) {
|
||||
workspaceID, err := oc.core.GetWorkspaceIdForObject(newID)
|
||||
if err != nil {
|
||||
// todo: GO-1304 I catch this during the import, we need find the root cause and fix it
|
||||
log.With(zap.String("object id", newID)).Errorf("failed to get workspace id %s: %s", newID, err.Error())
|
||||
}
|
||||
|
||||
|
|
|
@ -252,12 +252,16 @@ type PushChangeParams struct {
|
|||
State *state.State
|
||||
Changes []*pb.ChangeContent
|
||||
FileChangedHashes []string
|
||||
Time time.Time // used to derive the lastModifiedDate; Default is time.Now()
|
||||
DoSnapshot bool
|
||||
}
|
||||
|
||||
func (s *source) PushChange(params PushChangeParams) (id string, err error) {
|
||||
if params.Time.IsZero() {
|
||||
params.Time = time.Now()
|
||||
}
|
||||
c := &pb.Change{
|
||||
Timestamp: time.Now().Unix(),
|
||||
Timestamp: params.Time.Unix(),
|
||||
Version: params.State.MigrationVersion(),
|
||||
}
|
||||
if params.DoSnapshot || s.needSnapshot() || len(params.Changes) == 0 {
|
||||
|
|
|
@ -628,7 +628,7 @@ func (i *indexer) reindexOutdatedThreads() (toReindex, success int, err error) {
|
|||
func (i *indexer) reindexDoc(ctx context.Context, id string) error {
|
||||
_, isArchived := i.archivedMap[id]
|
||||
_, isFavorite := i.favoriteMap[id]
|
||||
|
||||
// todo: this may be racy because of reindexOutdatedThreads
|
||||
err := i.store.UpdatePendingLocalDetails(id, func(pending *types.Struct) (*types.Struct, error) {
|
||||
pending.Fields[bundle.RelationKeyIsArchived.String()] = pbtypes.Bool(isArchived)
|
||||
pending.Fields[bundle.RelationKeyIsFavorite.String()] = pbtypes.Bool(isFavorite)
|
||||
|
|
1
go.mod
1
go.mod
|
@ -89,6 +89,7 @@ require (
|
|||
go.uber.org/zap v1.24.0
|
||||
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb
|
||||
golang.org/x/image v0.6.0
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028
|
||||
golang.org/x/net v0.9.0
|
||||
golang.org/x/oauth2 v0.5.0
|
||||
golang.org/x/text v0.9.0
|
||||
|
|
1
go.sum
1
go.sum
|
@ -1029,6 +1029,7 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx
|
|||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs=
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue