Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: go/src/infra/appengine/test-results/model/test_file.go

Issue 2240473004: test-results: package frontend: add upload handler (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 package model 1 package model
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "io/ioutil" 7 "io/ioutil"
8 "math" 8 "math"
9 "time" 9 "time"
10 10
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 "model: data too large %d bytes (max allowed %d bytes)", 175 "model: data too large %d bytes (max allowed %d bytes)",
176 len(data), 176 len(data),
177 maxDataEntries*maxBlobLen, 177 maxDataEntries*maxBlobLen,
178 ) 178 )
179 } 179 }
180 180
181 // Break data into chunks of max. allowed blob length. 181 // Break data into chunks of max. allowed blob length.
182 numEntries := int(math.Ceil(float64(len(data)) / maxBlobLen)) 182 numEntries := int(math.Ceil(float64(len(data)) / maxBlobLen))
183 dataEntries := make([]DataEntry, 0, numEntries) 183 dataEntries := make([]DataEntry, 0, numEntries)
184 for i := 0; i < numEntries*maxBlobLen; i += maxBlobLen { 184 for i := 0; i < numEntries*maxBlobLen; i += maxBlobLen {
185 » » dataEntries = append(dataEntries, DataEntry{Data: data[i : i+max BlobLen]}) 185 » » end := min(i+maxBlobLen, len(data))
186 » » dataEntries = append(dataEntries, DataEntry{Data: data[i:end]})
186 } 187 }
187 188
188 if err := datastore.Get(c).Put(dataEntries); err != nil { 189 if err := datastore.Get(c).Put(dataEntries); err != nil {
189 return err 190 return err
190 } 191 }
191 192
192 newKeys := make([]*datastore.Key, 0, len(dataEntries)) 193 newKeys := make([]*datastore.Key, 0, len(dataEntries))
193 for _, de := range dataEntries { 194 for _, de := range dataEntries {
194 newKeys = append(newKeys, datastore.Get(c).KeyForObj(&de)) 195 newKeys = append(newKeys, datastore.Get(c).KeyForObj(&de))
195 } 196 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 q = q.Order("-date") 313 q = q.Order("-date")
313 314
314 if p.Limit < 0 || p.Limit > defaultLimit { 315 if p.Limit < 0 || p.Limit > defaultLimit {
315 q = q.Limit(defaultLimit) 316 q = q.Limit(defaultLimit)
316 } else { 317 } else {
317 q = q.Limit(p.Limit) 318 q = q.Limit(p.Limit)
318 } 319 }
319 320
320 return q 321 return q
321 } 322 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698