~evanj/cms

f758a22c9143a4e63cbb893b0685d1e7ab9d349b — Evan M Jones 4 months ago 60bdb33
Fix(db/content.go): Making sure all transactions are committed and
rolled back.
1 files changed, 4 insertions(+), 2 deletions(-)

M internal/s/db/content.go
M internal/s/db/content.go => internal/s/db/content.go +4 -2
@@ 871,6 871,7 @@ func (db *DB) ContentPerContentType(space space.Space, ct contenttype.ContentTyp
	if err != nil {
		return nil, err
	}
	defer t.Rollback()

	list, err := db.contentPerContentType(t, space, ct, before, order, sortField, defaultDepth)
	if err != nil {


@@ 897,6 898,7 @@ func (db *DB) ContentSearch(space space.Space, ct contenttype.ContentType, sortF
	if err != nil {
		return nil, err
	}
	defer t.Rollback()

	// Create temporary table for queries.
	tbl := fmt.Sprintf("cms_tmp_cl_search_%s", strings.ReplaceAll(uuid.New().String(), "-", "_"))


@@ 958,7 960,7 @@ func (db *DB) ContentSearch(space space.Space, ct contenttype.ContentType, sortF
			return nil, err
		}

		c, err := db.ContentGet(space, ct, tmpContentID)
		c, err := db.contentGet(t, space, ct, tmpContentID, defaultDepth)
		if err != nil {
			return nil, err
		}


@@ 966,7 968,7 @@ func (db *DB) ContentSearch(space space.Space, ct contenttype.ContentType, sortF
		r = append(r, c)
	}

	return newContentList(r, hasMore, tmpID), nil
	return newContentList(r, hasMore, tmpID), t.Commit()
}

func (db *DB) contentGet(t *sql.Tx, space space.Space, ct contenttype.ContentType, contentID string, depth int) (content.Content, error) {