mirror of
https://github.com/usememos/memos.git
synced 2024-11-24 06:35:24 +03:00
chore: remove unused functions
This commit is contained in:
parent
88728906a8
commit
52f399a154
@ -212,38 +212,6 @@ func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DB) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]store.Visibility, error) {
|
||||
args := make([]any, 0, len(memoIDs))
|
||||
list := make([]string, 0, len(memoIDs))
|
||||
for _, memoID := range memoIDs {
|
||||
args = append(args, memoID)
|
||||
list = append(list, "?")
|
||||
}
|
||||
|
||||
where := fmt.Sprintf("`id` in (%s)", strings.Join(list, ","))
|
||||
query := "SELECT DISTINCT(`visibility`) FROM `memo` WHERE " + where
|
||||
rows, err := d.db.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
visibilityList := make([]store.Visibility, 0)
|
||||
for rows.Next() {
|
||||
var visibility store.Visibility
|
||||
if err := rows.Scan(&visibility); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
visibilityList = append(visibilityList, visibility)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return visibilityList, nil
|
||||
}
|
||||
|
||||
func vacuumMemo(ctx context.Context, tx *sql.Tx) error {
|
||||
stmt := "DELETE FROM `memo` WHERE `creator_id` NOT IN (SELECT `id` FROM `user`)"
|
||||
_, err := tx.ExecContext(ctx, stmt)
|
||||
|
@ -232,19 +232,8 @@ func (d *DB) UpdateMemo(ctx context.Context, update *store.UpdateMemo) error {
|
||||
}
|
||||
|
||||
func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {
|
||||
// Start building the DELETE statement
|
||||
builder := squirrel.Delete("memo").
|
||||
PlaceholderFormat(squirrel.Dollar).
|
||||
Where(squirrel.Eq{"id": delete.ID})
|
||||
|
||||
// Prepare the final query
|
||||
query, args, err := builder.ToSql()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Execute the query with the context
|
||||
result, err := d.db.ExecContext(ctx, query, args...)
|
||||
stmt := `DELETE FROM memo WHERE id = $1`
|
||||
result, err := d.db.ExecContext(ctx, stmt, delete.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -253,49 +242,9 @@ func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Perform any additional cleanup or operations such as vacuuming
|
||||
// irving: wait, why do we need to vacuum here?
|
||||
// I don't know why delete memo needs to vacuum. so I commented out.
|
||||
// REVIEWERS LOOK AT ME: please check this.
|
||||
|
||||
return d.Vacuum(ctx)
|
||||
}
|
||||
|
||||
func (d *DB) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]store.Visibility, error) {
|
||||
// Start building the SELECT statement
|
||||
builder := squirrel.Select("DISTINCT(visibility)").From("memo").
|
||||
PlaceholderFormat(squirrel.Dollar).
|
||||
Where(squirrel.Eq{"id": memoIDs})
|
||||
|
||||
// Prepare the final query
|
||||
query, args, err := builder.ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Execute the query with the context
|
||||
rows, err := d.db.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
visibilityList := make([]store.Visibility, 0)
|
||||
for rows.Next() {
|
||||
var visibility store.Visibility
|
||||
if err := rows.Scan(&visibility); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
visibilityList = append(visibilityList, visibility)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return visibilityList, nil
|
||||
}
|
||||
|
||||
func vacuumMemo(ctx context.Context, tx *sql.Tx) error {
|
||||
// First, build the subquery
|
||||
subQuery, subArgs, err := squirrel.Select("id").From("user").PlaceholderFormat(squirrel.Dollar).ToSql()
|
||||
|
@ -205,38 +205,6 @@ func (d *DB) DeleteMemo(ctx context.Context, delete *store.DeleteMemo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DB) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]store.Visibility, error) {
|
||||
args := make([]any, 0, len(memoIDs))
|
||||
list := make([]string, 0, len(memoIDs))
|
||||
for _, memoID := range memoIDs {
|
||||
args = append(args, memoID)
|
||||
list = append(list, "?")
|
||||
}
|
||||
|
||||
where := fmt.Sprintf("id in (%s)", strings.Join(list, ","))
|
||||
query := `SELECT DISTINCT(visibility) FROM memo WHERE ` + where
|
||||
rows, err := d.db.QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
visibilityList := make([]store.Visibility, 0)
|
||||
for rows.Next() {
|
||||
var visibility store.Visibility
|
||||
if err := rows.Scan(&visibility); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
visibilityList = append(visibilityList, visibility)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return visibilityList, nil
|
||||
}
|
||||
|
||||
func vacuumMemo(ctx context.Context, tx *sql.Tx) error {
|
||||
stmt := `
|
||||
DELETE FROM
|
||||
|
@ -39,7 +39,6 @@ type Driver interface {
|
||||
ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error)
|
||||
UpdateMemo(ctx context.Context, update *UpdateMemo) error
|
||||
DeleteMemo(ctx context.Context, delete *DeleteMemo) error
|
||||
FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]Visibility, error)
|
||||
|
||||
// MemoRelation model related methods.
|
||||
UpsertMemoRelation(ctx context.Context, create *MemoRelation) (*MemoRelation, error)
|
||||
|
@ -108,7 +108,3 @@ func (s *Store) UpdateMemo(ctx context.Context, update *UpdateMemo) error {
|
||||
func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error {
|
||||
return s.driver.DeleteMemo(ctx, delete)
|
||||
}
|
||||
|
||||
func (s *Store) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]Visibility, error) {
|
||||
return s.driver.FindMemosVisibilityList(ctx, memoIDs)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user