- commit
- ada4909
- parent
- 76d15e5
- author
- Eric Bower
- date
- 2023-09-27 13:22:11 +0000 UTC
fix(imgs): when calc user's total img size, coalesce null to 0 chore: add more error logging for us to debug
4 files changed,
+13,
-3
+1,
-1
1@@ -158,7 +158,7 @@ const (
2 sqlSelectUsersWithPost = `SELECT count(app_users.id) FROM app_users WHERE EXISTS (SELECT 1 FROM posts WHERE user_id = app_users.id AND cur_space = $1);`
3
4 sqlSelectFeatureForUser = `SELECT id FROM feature_flags WHERE user_id = $1 AND name = $2`
5- sqlSelectSizeForUser = `SELECT sum(file_size) FROM posts WHERE user_id = $1`
6+ sqlSelectSizeForUser = `SELECT COALESCE(sum(file_size), 0) FROM posts WHERE user_id = $1`
7
8 sqlSelectPostIdByAliasSlug = `SELECT post_id FROM post_aliases WHERE slug = $1`
9 sqlSelectTagPostCount = `
+6,
-0
1@@ -177,6 +177,7 @@ func (h *UploadAssetHandler) Validate(s ssh.Session) error {
2 func (h *UploadAssetHandler) Write(s ssh.Session, entry *utils.FileEntry) (string, error) {
3 user, err := getUser(s)
4 if err != nil {
5+ h.Cfg.Logger.Error(err)
6 return "", err
7 }
8
9@@ -191,6 +192,7 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *utils.FileEntry) (strin
10
11 bucket, err := getBucket(s)
12 if err != nil {
13+ h.Cfg.Logger.Error(err)
14 return "", err
15 }
16
17@@ -203,15 +205,18 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *utils.FileEntry) (strin
18 if err == nil {
19 err = h.DBPool.UpdateProject(user.ID, projectName)
20 if err != nil {
21+ h.Cfg.Logger.Error(err)
22 return "", err
23 }
24 } else {
25 _, err = h.DBPool.InsertProject(user.ID, projectName, projectName)
26 if err != nil {
27+ h.Cfg.Logger.Error(err)
28 return "", err
29 }
30 project, err = h.DBPool.FindProjectByName(user.ID, projectName)
31 if err != nil {
32+ h.Cfg.Logger.Error(err)
33 return "", err
34 }
35 }
36@@ -228,6 +233,7 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *utils.FileEntry) (strin
37 }
38 err = h.writeAsset(data)
39 if err != nil {
40+ h.Cfg.Logger.Error(err)
41 return "", err
42 }
43
+4,
-1
1@@ -178,6 +178,7 @@ func (h *UploadImgHandler) Validate(s ssh.Session) error {
2 func (h *UploadImgHandler) Write(s ssh.Session, entry *utils.FileEntry) (string, error) {
3 user, err := getUser(s)
4 if err != nil {
5+ h.Cfg.Logger.Error(err)
6 return "", err
7 }
8
9@@ -233,7 +234,7 @@ func (h *UploadImgHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
10 h.Cfg.Space,
11 )
12 if err != nil {
13- h.Cfg.Logger.Infof("(%s) unable to find post (%s), continuing", nextPost.Filename, err)
14+ h.Cfg.Logger.Infof("(%s) unable to find image (%s), continuing", nextPost.Filename, err)
15 }
16
17 metadata := PostMetaData{
18@@ -250,11 +251,13 @@ func (h *UploadImgHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
19
20 err = h.writeImg(s, &metadata)
21 if err != nil {
22+ h.Cfg.Logger.Error(err)
23 return "", err
24 }
25
26 totalFileSize, err := h.DBPool.FindTotalSizeForUser(user.ID)
27 if err != nil {
28+ h.Cfg.Logger.Error(err)
29 return "", err
30 }
31
+2,
-1
1@@ -158,6 +158,7 @@ func (h *ScpUploadHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
2 logger := h.Cfg.Logger
3 user, err := getUser(s)
4 if err != nil {
5+ logger.Error(err)
6 return "", err
7 }
8
9@@ -203,7 +204,7 @@ func (h *ScpUploadHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
10
11 valid, err := h.Hooks.FileValidate(&metadata)
12 if !valid {
13- logger.Info(err)
14+ logger.Error(err)
15 return "", err
16 }
17