processFragments categorizes items in sync fragments into a sync list.
(fragments []client.SyncFragment)
| 97 | |
| 98 | // processFragments categorizes items in sync fragments into a sync list. |
| 99 | func processFragments(fragments []client.SyncFragment) (syncList, error) { |
| 100 | notes := map[string]client.SyncFragNote{} |
| 101 | books := map[string]client.SyncFragBook{} |
| 102 | expungedNotes := map[string]bool{} |
| 103 | expungedBooks := map[string]bool{} |
| 104 | var maxUSN int |
| 105 | var userMaxUSN int |
| 106 | var maxCurrentTime int64 |
| 107 | |
| 108 | for _, fragment := range fragments { |
| 109 | for _, note := range fragment.Notes { |
| 110 | notes[note.UUID] = note |
| 111 | } |
| 112 | for _, book := range fragment.Books { |
| 113 | books[book.UUID] = book |
| 114 | } |
| 115 | for _, uuid := range fragment.ExpungedBooks { |
| 116 | expungedBooks[uuid] = true |
| 117 | } |
| 118 | for _, uuid := range fragment.ExpungedNotes { |
| 119 | expungedNotes[uuid] = true |
| 120 | } |
| 121 | |
| 122 | if fragment.FragMaxUSN > maxUSN { |
| 123 | maxUSN = fragment.FragMaxUSN |
| 124 | } |
| 125 | if fragment.UserMaxUSN > userMaxUSN { |
| 126 | userMaxUSN = fragment.UserMaxUSN |
| 127 | } |
| 128 | if fragment.CurrentTime > maxCurrentTime { |
| 129 | maxCurrentTime = fragment.CurrentTime |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | sl := syncList{ |
| 134 | Notes: notes, |
| 135 | Books: books, |
| 136 | ExpungedNotes: expungedNotes, |
| 137 | ExpungedBooks: expungedBooks, |
| 138 | MaxUSN: maxUSN, |
| 139 | UserMaxUSN: userMaxUSN, |
| 140 | MaxCurrentTime: maxCurrentTime, |
| 141 | } |
| 142 | |
| 143 | return sl, nil |
| 144 | } |
| 145 | |
| 146 | // getSyncList gets a list of all sync fragments after the specified usn |
| 147 | // and aggregates them into a syncList data structure |
no outgoing calls