@@ -109,47 +109,42 @@ func airtableSync(opts *airtableOptions) error {
109
109
110
110
// unique entries
111
111
features := make ([]map [string ]repo.Feature , airtabledb .NumTables )
112
+ for i , _ := range features {
113
+ features [i ] = make (map [string ]repo.Feature )
114
+ }
112
115
113
116
for _ , issue := range filtered {
114
117
// providers
115
- //providerMap[issue.Repository.Provider.ID] = issue.Repository.Provider
116
118
features [airtabledb .ProviderIndex ][issue .Repository .Provider .ID ] = issue .Repository .Provider
117
119
118
120
// labels
119
121
for _ , label := range issue .Labels {
120
- //labelMap[label.ID] = label
121
122
features [airtabledb.LabelIndex ][label.ID ] = label
122
123
}
123
124
124
125
// accounts
125
126
if issue .Repository .Owner != nil {
126
- //accountMap[issue.Repository.Owner.ID] = issue.Repository.Owner
127
127
features [airtabledb .AccountIndex ][issue .Repository .Owner .ID ] = issue .Repository .Owner
128
128
}
129
- //accountMap[issue.Author.ID] = issue.Author
129
+
130
130
features [airtabledb .AccountIndex ][issue .Author .ID ] = issue .Author
131
131
for _ , assignee := range issue .Assignees {
132
- //accountMap[assignee.ID] = assignee
133
132
features [airtabledb.AccountIndex ][assignee.ID ] = assignee
134
133
}
135
134
if issue .Milestone != nil && issue .Milestone .Creator != nil {
136
- //accountMap[issue.Milestone.Creator.ID] = issue.Milestone.Creator
137
135
features [airtabledb .AccountIndex ][issue .Milestone .Creator .ID ] = issue .Milestone .Creator
138
136
}
139
137
140
138
// repositories
141
- //repositoryMap[issue.Repository.ID] = issue.Repository
142
139
features [airtabledb .RepositoryIndex ][issue .Repository .ID ] = issue .Repository
143
140
// FIXME: find external repositories based on depends-on links
144
141
145
142
// milestones
146
143
if issue .Milestone != nil {
147
- //milestoneMap[issue.Milestone.ID] = issue.Milestone
148
144
features [airtabledb .MilestoneIndex ][issue .Milestone .ID ] = issue .Milestone
149
145
}
150
146
151
147
// issue
152
- //issueMap[issue.ID] = issue
153
148
features [airtabledb.IssueIndex ][issue.ID ] = issue
154
149
// FIXME: find external issues based on depends-on links
155
150
}
@@ -165,8 +160,7 @@ func airtableSync(opts *airtableOptions) error {
165
160
cache := airtabledb .NewDB ()
166
161
for tableKind , tableName := range opts .TableNames {
167
162
table := at .Table (tableName )
168
- records := cache .Tables [tableKind ]
169
- if err := table .List (& records , & airtable.Options {}); err != nil {
163
+ if err := cache .Tables [tableKind ].Fetch (table ); err != nil {
170
164
return err
171
165
}
172
166
}
@@ -181,20 +175,21 @@ func airtableSync(opts *airtableOptions) error {
181
175
for _ , dbEntry := range featureMap {
182
176
matched := false
183
177
dbRecord := dbEntry .ToRecord (cache )
184
- for idx , atEntry := range cache .Tables [tableKind ] {
185
- if atEntry .Fields .ID == dbEntry .GetID () {
186
- if atEntry .Equals (dbRecord ) {
187
- cache.Tables [tableKind ][idx ].State = airtabledb .StateUnchanged
178
+ for idx := 0 ; idx < cache .Tables [tableKind ].Len (); idx ++ {
179
+ t := cache .Tables [tableKind ]
180
+ if t .GetFieldID (idx ) == dbEntry .GetID () {
181
+ if t .RecordsEqual (idx , dbRecord ) {
182
+ t .SetState (idx , airtabledb .StateUnchanged )
188
183
} else {
189
- cache. Tables [ tableKind ][ idx ]. Fields = dbRecord . Fields
190
- cache. Tables [ tableKind ][ idx ]. State = airtabledb .StateChanged
184
+ t . CopyFields ( idx , dbRecord )
185
+ t . SetState ( idx , airtabledb .StateChanged )
191
186
}
192
187
matched = true
193
188
break
194
189
}
195
190
}
196
191
if ! matched {
197
- unmatched .Tables [tableKind ] = append ( unmatched . Tables [ tableKind ], dbRecord )
192
+ unmatched .Tables [tableKind ]. Append ( dbRecord )
198
193
}
199
194
}
200
195
}
@@ -204,28 +199,30 @@ func airtableSync(opts *airtableOptions) error {
204
199
//
205
200
for tableKind , tableName := range opts .TableNames {
206
201
table := at .Table (tableName )
207
- for _ , entry := range unmatched .Tables [tableKind ] {
208
- zap .L ().Debug ("create airtable entry" , zap .String ("type" , tableName ), zap .Stringer ("entry" , entry ))
209
- if err := table .Create (& entry ); err != nil {
202
+ ut := unmatched .Tables [tableKind ]
203
+ ct := cache .Tables [tableKind ]
204
+ for i := 0 ; i < ut .Len (); i ++ {
205
+ zap .L ().Debug ("create airtable entry" , zap .String ("type" , tableName ), zap .String ("entry" , ut .StringAt (i )))
206
+ if err := table .Create (ut .GetPtr (i )); err != nil {
210
207
return err
211
208
}
212
- entry . State = airtabledb .StateNew
213
- cache . Tables [ tableKind ] = append ( cache . Tables [ tableKind ], entry )
209
+ ut . SetState ( i , airtabledb .StateNew )
210
+ ct . Append ( ut . Get ( i ) )
214
211
}
215
- for _ , entry := range cache . Tables [ tableKind ] {
212
+ for i := 0 ; i < ct . Len (); i ++ {
216
213
var err error
217
- switch entry . State {
214
+ switch ct . GetState ( i ) {
218
215
case airtabledb .StateUnknown :
219
- err = table .Delete (& entry )
220
- zap .L ().Debug ("delete airtable entry" , zap .String ("type" , tableName ), zap .Stringer ("entry" , entry ), zap .Error (err ))
216
+ err = table .Delete (ct . GetPtr ( i ) )
217
+ zap .L ().Debug ("delete airtable entry" , zap .String ("type" , tableName ), zap .String ("entry" , ct . StringAt ( i ) ), zap .Error (err ))
221
218
case airtabledb .StateChanged :
222
- err = table .Update (& entry )
223
- zap .L ().Debug ("update airtable entry" , zap .String ("type" , tableName ), zap .Stringer ("entry" , entry ), zap .Error (err ))
219
+ err = table .Update (ct . GetPtr ( i ) )
220
+ zap .L ().Debug ("update airtable entry" , zap .String ("type" , tableName ), zap .String ("entry" , ct . StringAt ( i ) ), zap .Error (err ))
224
221
case airtabledb .StateUnchanged :
225
- zap .L ().Debug ("unchanged airtable entry" , zap .String ("type" , tableName ), zap .Stringer ("entry" , entry ), zap .Error (err ))
222
+ zap .L ().Debug ("unchanged airtable entry" , zap .String ("type" , tableName ), zap .String ("entry" , ct . StringAt ( i ) ), zap .Error (err ))
226
223
// do nothing
227
224
case airtabledb .StateNew :
228
- zap .L ().Debug ("new airtable entry" , zap .String ("type" , tableName ), zap .Stringer ("entry" , entry ), zap .Error (err ))
225
+ zap .L ().Debug ("new airtable entry" , zap .String ("type" , tableName ), zap .String ("entry" , ct . StringAt ( i ) ), zap .Error (err ))
229
226
// do nothing
230
227
}
231
228
}
@@ -236,8 +233,9 @@ func airtableSync(opts *airtableOptions) error {
236
233
//
237
234
for tableKind , tableName := range opts .TableNames {
238
235
fmt .Println ("-------" , tableName )
239
- for _ , entry := range cache .Tables [tableKind ] {
240
- fmt .Println (entry .ID , airtabledb .StateString [entry .State ], entry .Fields .ID )
236
+ ct := cache .Tables [tableKind ]
237
+ for i := 0 ; i < ct .Len (); i ++ {
238
+ fmt .Println (ct .GetID (i ), airtabledb .StateString [ct .GetState (i )], ct .GetFieldID (i ))
241
239
}
242
240
}
243
241
fmt .Println ("-------" )
0 commit comments