diff --git a/src/db/rdb/sqlite/files.go b/src/db/rdb/sqlite/files.go index 88ec81b..7b0ae2c 100644 --- a/src/db/rdb/sqlite/files.go +++ b/src/db/rdb/sqlite/files.go @@ -12,17 +12,6 @@ import ( "github.com/ihexxa/quickshare/src/db" ) -const ( - InitNs = "Init" - InitTimeKey = "initTime" - SchemaVerKey = "SchemaVersion" - SchemaV1 = "v1" -) - -var ( - maxHashingTime = 10 -) - func (st *SQLiteStore) getFileInfo(ctx context.Context, itemPath string) (*db.FileInfo, error) { var infoStr string fInfo := &db.FileInfo{} diff --git a/src/db/rdb/sqlite/files_sharings.go b/src/db/rdb/sqlite/files_sharings.go index ecf30d7..e40c246 100644 --- a/src/db/rdb/sqlite/files_sharings.go +++ b/src/db/rdb/sqlite/files_sharings.go @@ -154,7 +154,7 @@ func (st *SQLiteStore) ListSharingsByLocation(ctx context.Context, location stri ctx, `select path, share_id from t_file_info - where location=? and share_id<>''`, + where share_id<>'' and location=?`, location, ) if err != nil { diff --git a/src/db/rdb/sqlite/files_uploadings.go b/src/db/rdb/sqlite/files_uploadings.go index 9439365..86d38fb 100644 --- a/src/db/rdb/sqlite/files_uploadings.go +++ b/src/db/rdb/sqlite/files_uploadings.go @@ -137,8 +137,8 @@ func (st *SQLiteStore) getUploadInfo(ctx context.Context, userId uint64, filePat ctx, `select size, uploaded from t_file_uploading - where user=? and real_path=?`, - userId, filePath, + where real_path=? and user=?`, + filePath, userId, ).Scan(&size, &uploaded) if err != nil { return "", 0, 0, err diff --git a/src/db/rdb/sqlite/sqlite.go b/src/db/rdb/sqlite/sqlite.go index 88541df..bdfd045 100644 --- a/src/db/rdb/sqlite/sqlite.go +++ b/src/db/rdb/sqlite/sqlite.go @@ -76,7 +76,7 @@ func (st *SQLiteStore) InitUserTable(ctx context.Context, rootName, rootPwd stri ctx, `create table if not exists t_user ( id bigint not null, - name varchar not null, + name varchar not null unique, pwd varchar not null, role integer not null, used_space bigint not null, @@ -89,6 +89,14 @@ func (st *SQLiteStore) InitUserTable(ctx context.Context, rootName, rootPwd stri return err } + _, err = st.db.ExecContext( + ctx, + `create index i_user_name on t_user (name)`, + ) + if err != nil { + return err + } + admin := &db.User{ ID: 0, Name: rootName, @@ -143,17 +151,41 @@ func (st *SQLiteStore) InitFileTables(ctx context.Context) error { return err } + _, err = st.db.ExecContext( + ctx, + `create index t_file_share on t_file_info (share_id, location)`, + ) + if err != nil { + return err + } + _, err = st.db.ExecContext( ctx, `create table if not exists t_file_uploading ( real_path varchar not null, - tmp_path varchar not null, + tmp_path varchar not null unique, user bigint not null, size bigint not null, uploaded bigint not null, primary key(real_path) )`, ) + if err != nil { + return err + } + + _, err = st.db.ExecContext( + ctx, + `create index t_file_uploading_path on t_file_uploading (real_path, user)`, + ) + if err != nil { + return err + } + + _, err = st.db.ExecContext( + ctx, + `create index t_file_uploading_user on t_file_uploading (user)`, + ) return err }