-
Notifications
You must be signed in to change notification settings - Fork 27
/
CompletionOps.swift
68 lines (55 loc) · 2.47 KB
/
CompletionOps.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
import Shared
import XCGLogger
private let log = Logger.syncLogger
public protocol PerhapsNoOp {
var isNoOp: Bool { get }
}
open class LocalOverrideCompletionOp: PerhapsNoOp {
open var processedLocalChanges: Set<GUID> = Set() // These can be deleted when we're run. Mark mirror as non-overridden, too.
open var mirrorItemsToDelete: Set<GUID> = Set() // These were locally or remotely deleted.
open var mirrorItemsToInsert: [GUID: BookmarkMirrorItem] = [:] // These were locally or remotely added.
open var mirrorItemsToUpdate: [GUID: BookmarkMirrorItem] = [:] // These were already in the mirror, but changed.
open var mirrorStructures: [GUID: [GUID]] = [:] // New or changed structure.
open var mirrorValuesToCopyFromBuffer: Set<GUID> = Set() // No need to synthesize BookmarkMirrorItem instances in memory.
open var mirrorValuesToCopyFromLocal: Set<GUID> = Set()
open var modifiedTimes: [Timestamp: [GUID]] = [:] // Only for copy.
open var isNoOp: Bool {
return processedLocalChanges.isEmpty &&
mirrorValuesToCopyFromBuffer.isEmpty &&
mirrorValuesToCopyFromLocal.isEmpty &&
mirrorItemsToDelete.isEmpty &&
mirrorItemsToInsert.isEmpty &&
mirrorItemsToUpdate.isEmpty &&
mirrorStructures.isEmpty
}
open func setModifiedTime(_ time: Timestamp, guids: [GUID]) {
var forCopy: [GUID] = self.modifiedTimes[time] ?? []
for guid in guids {
// This saves us doing an UPDATE on these items.
if var item = self.mirrorItemsToInsert[guid] {
item.serverModified = time
} else if var item = self.mirrorItemsToUpdate[guid] {
item.serverModified = time
} else {
forCopy.append(guid)
}
}
if !forCopy.isEmpty {
modifiedTimes[time] = forCopy
}
}
public init() {
}
}
open class BufferCompletionOp: PerhapsNoOp {
open var processedBufferChanges: Set<GUID> = Set() // These can be deleted when we're run.
open var isNoOp: Bool {
return self.processedBufferChanges.isEmpty
}
public init() {
}
}