fix(sqlite): add indexes and unique constraint
This commit is contained in:
parent
df5c820c68
commit
d97451653e
4 changed files with 37 additions and 16 deletions
|
@ -12,17 +12,6 @@ import (
|
||||||
"github.com/ihexxa/quickshare/src/db"
|
"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) {
|
func (st *SQLiteStore) getFileInfo(ctx context.Context, itemPath string) (*db.FileInfo, error) {
|
||||||
var infoStr string
|
var infoStr string
|
||||||
fInfo := &db.FileInfo{}
|
fInfo := &db.FileInfo{}
|
||||||
|
|
|
@ -154,7 +154,7 @@ func (st *SQLiteStore) ListSharingsByLocation(ctx context.Context, location stri
|
||||||
ctx,
|
ctx,
|
||||||
`select path, share_id
|
`select path, share_id
|
||||||
from t_file_info
|
from t_file_info
|
||||||
where location=? and share_id<>''`,
|
where share_id<>'' and location=?`,
|
||||||
location,
|
location,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -137,8 +137,8 @@ func (st *SQLiteStore) getUploadInfo(ctx context.Context, userId uint64, filePat
|
||||||
ctx,
|
ctx,
|
||||||
`select size, uploaded
|
`select size, uploaded
|
||||||
from t_file_uploading
|
from t_file_uploading
|
||||||
where user=? and real_path=?`,
|
where real_path=? and user=?`,
|
||||||
userId, filePath,
|
filePath, userId,
|
||||||
).Scan(&size, &uploaded)
|
).Scan(&size, &uploaded)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, 0, err
|
return "", 0, 0, err
|
||||||
|
|
|
@ -76,7 +76,7 @@ func (st *SQLiteStore) InitUserTable(ctx context.Context, rootName, rootPwd stri
|
||||||
ctx,
|
ctx,
|
||||||
`create table if not exists t_user (
|
`create table if not exists t_user (
|
||||||
id bigint not null,
|
id bigint not null,
|
||||||
name varchar not null,
|
name varchar not null unique,
|
||||||
pwd varchar not null,
|
pwd varchar not null,
|
||||||
role integer not null,
|
role integer not null,
|
||||||
used_space bigint not null,
|
used_space bigint not null,
|
||||||
|
@ -89,6 +89,14 @@ func (st *SQLiteStore) InitUserTable(ctx context.Context, rootName, rootPwd stri
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, err = st.db.ExecContext(
|
||||||
|
ctx,
|
||||||
|
`create index i_user_name on t_user (name)`,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
admin := &db.User{
|
admin := &db.User{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Name: rootName,
|
Name: rootName,
|
||||||
|
@ -143,17 +151,41 @@ func (st *SQLiteStore) InitFileTables(ctx context.Context) error {
|
||||||
return err
|
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(
|
_, err = st.db.ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
`create table if not exists t_file_uploading (
|
`create table if not exists t_file_uploading (
|
||||||
real_path varchar not null,
|
real_path varchar not null,
|
||||||
tmp_path varchar not null,
|
tmp_path varchar not null unique,
|
||||||
user bigint not null,
|
user bigint not null,
|
||||||
size bigint not null,
|
size bigint not null,
|
||||||
uploaded bigint not null,
|
uploaded bigint not null,
|
||||||
primary key(real_path)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue