aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-01-23 08:56:51 +0000
committerLauris BH <lauris@nix.lv>2019-01-23 10:56:51 +0200
commit7d434376f1504ff64f249b879634ac2eec9440da (patch)
tree3a722ee5c0ceb64fff959d0431939f8b6b3f8662 /models
parent075649572d4472b588a8484ce3d7c37df7621f85 (diff)
downloadgitea-7d434376f1504ff64f249b879634ac2eec9440da.tar.gz
gitea-7d434376f1504ff64f249b879634ac2eec9440da.zip
Pooled and buffered gzip implementation (#5722)
* Pooled and buffered gzip implementation * Add test for gzip * Add integration test * Ensure lfs check within transaction The previous code made it possible for a race condition to occur whereby a LFSMetaObject could be checked into the database twice. We should check if the LFSMetaObject is within the database and insert it if not in one transaction. * Try to avoid primary key problem in postgres The integration tests are being affected by https://github.com/go-testfixtures/testfixtures/issues/39 if we set the primary key high enough, keep a count of this and remove at the end of each test we shouldn't be affected by this.
Diffstat (limited to 'models')
-rw-r--r--models/lfs.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/models/lfs.go b/models/lfs.go
index 711e5b0494..39b0b2dd69 100644
--- a/models/lfs.go
+++ b/models/lfs.go
@@ -44,20 +44,20 @@ const (
func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) {
var err error
- has, err := x.Get(m)
+ sess := x.NewSession()
+ defer sess.Close()
+ if err = sess.Begin(); err != nil {
+ return nil, err
+ }
+
+ has, err := sess.Get(m)
if err != nil {
return nil, err
}
if has {
m.Existing = true
- return m, nil
- }
-
- sess := x.NewSession()
- defer sess.Close()
- if err = sess.Begin(); err != nil {
- return nil, err
+ return m, sess.Commit()
}
if _, err = sess.Insert(m); err != nil {