Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Neos
Commits
770af6f9
Commit
770af6f9
authored
Aug 13, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize fts.ts
parent
72a57075
Pipeline
#23049
passed with stages
in 13 minutes and 50 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
92 deletions
+11
-92
src/api/forbiddens.ts
src/api/forbiddens.ts
+2
-4
src/middleware/sqlite/fts.ts
src/middleware/sqlite/fts.ts
+9
-5
src/stores/forbiddenStore.ts
src/stores/forbiddenStore.ts
+0
-83
No files found.
src/api/forbiddens.ts
View file @
770af6f9
//! 禁限卡表
//! 禁限卡表
import
{
clear
,
createStore
,
get
,
set
}
from
"
idb-keyval
"
;
import
{
clear
,
createStore
,
get
,
set
Many
}
from
"
idb-keyval
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
useConfig
}
from
"
@/config
"
;
...
@@ -23,9 +23,7 @@ export async function initForbiddens(): Promise<void> {
...
@@ -23,9 +23,7 @@ export async function initForbiddens(): Promise<void> {
// 先清掉之前的记录
// 先清掉之前的记录
clear
(
idb
);
clear
(
idb
);
// 设置新记录
// 设置新记录
await
Promise
.
all
(
await
setMany
(
Array
.
from
(
forbiddens
));
Array
.
from
(
forbiddens
).
map
(([
key
,
value
])
=>
set
(
key
,
value
,
idb
))
);
}
}
// 获取禁限信息
// 获取禁限信息
...
...
src/middleware/sqlite/fts.ts
View file @
770af6f9
...
@@ -26,7 +26,14 @@ export function invokeFts(db: Database, params: FtsParams): CardMeta[] {
...
@@ -26,7 +26,14 @@ export function invokeFts(db: Database, params: FtsParams): CardMeta[] {
const
ftsTexts
:
CardText
[]
=
[];
const
ftsTexts
:
CardText
[]
=
[];
const
ftsMetas
:
CardMeta
[]
=
[];
const
ftsMetas
:
CardMeta
[]
=
[];
const
textStmt
=
db
.
prepare
(
"
SELECT * FROM texts WHERE name LIKE $query
"
);
const
filterConditions
=
getFtsCondtions
(
conditions
);
const
textStmt
=
db
.
prepare
(
`SELECT * FROM texts INNER JOIN datas ON texts.id = datas.id
${
filterConditions
==
""
?
"
WHERE name LIKE $query
"
:
`WHERE name LIKE $query AND
${
filterConditions
}
`
}
`
);
textStmt
.
bind
({
$query
:
`%
${
query
}
%`
});
textStmt
.
bind
({
$query
:
`%
${
query
}
%`
});
while
(
textStmt
.
step
())
{
while
(
textStmt
.
step
())
{
...
@@ -37,10 +44,7 @@ export function invokeFts(db: Database, params: FtsParams): CardMeta[] {
...
@@ -37,10 +44,7 @@ export function invokeFts(db: Database, params: FtsParams): CardMeta[] {
for
(
const
text
of
ftsTexts
)
{
for
(
const
text
of
ftsTexts
)
{
const
id
=
text
.
id
;
const
id
=
text
.
id
;
if
(
id
)
{
if
(
id
)
{
const
filterConditions
=
getFtsCondtions
(
conditions
);
const
sql
=
"
SELECT * FROM datas WHERE ID = $id
"
;
const
sql
=
`SELECT * FROM datas WHERE
${
filterConditions
==
""
?
"
ID = $id
"
:
`ID = $id AND
${
filterConditions
}
`
}
`
;
const
dataStmt
=
db
.
prepare
(
sql
);
const
dataStmt
=
db
.
prepare
(
sql
);
const
data
:
CardData
=
dataStmt
.
getAsObject
({
$id
:
id
});
const
data
:
CardData
=
dataStmt
.
getAsObject
({
$id
:
id
});
if
(
Object
.
values
(
data
).
filter
((
v
)
=>
v
!==
undefined
).
length
>
0
)
{
if
(
Object
.
values
(
data
).
filter
((
v
)
=>
v
!==
undefined
).
length
>
0
)
{
...
...
src/stores/forbiddenStore.ts
deleted
100644 → 0
View file @
72a57075
//! 禁限卡表
import
{
clear
,
createStore
,
get
,
set
}
from
"
idb-keyval
"
;
import
{
useConfig
}
from
"
@/config
"
;
const
{
lflistUrl
}
=
useConfig
();
type
Forbiddens
=
Map
<
number
,
number
>
;
const
IDB_NAME
=
"
forbiddens
"
;
// 禁限卡表的时间,比如 [2023.4] - 2023年4月表
export
let
forbiddenTime
=
"
?
"
;
const
idb
=
createStore
(
IDB_NAME
,
IDB_NAME
);
export
async
function
init
():
Promise
<
void
>
{
const
text
=
await
(
await
fetch
(
lflistUrl
)).
text
();
const
{
time
,
forbiddens
}
=
extractForbiddensFromText
(
text
);
forbiddenTime
=
time
;
// 先清掉之前的记录
clear
(
idb
);
// 设置新记录
await
Promise
.
all
(
Array
.
from
(
forbiddens
).
map
(([
key
,
value
])
=>
set
(
key
,
value
,
idb
))
);
}
// 获取禁限信息
export
async
function
getForbiddenInfo
(
id
:
number
):
Promise
<
number
|
undefined
>
{
return
await
get
(
id
,
idb
);
}
// 解析函数,提取卡片编号和限制张数
function
parseCardInfo
(
input
:
string
):
{
cardId
:
number
;
limitCount
:
number
}
|
null
{
const
match
=
input
.
match
(
/^
(\d
+
)\s
+
(\d
+
)\s
+--/
);
if
(
match
)
{
const
cardId
=
parseInt
(
match
[
1
]);
const
limitCount
=
parseInt
(
match
[
2
]);
return
{
cardId
,
limitCount
};
}
return
null
;
}
// 分割文本为行,并提取每行的限制信息
function
extractForbiddensFromText
(
text
:
string
):
{
time
:
string
;
forbiddens
:
Forbiddens
;
}
{
const
lines
=
text
.
split
(
"
\n
"
);
const
forbiddens
=
new
Map
<
number
,
number
>
([]);
// remove first line
lines
.
shift
();
let
time
=
"
?
"
;
for
(
const
line
of
lines
)
{
if
(
line
.
startsWith
(
"
#
"
))
{
// do nothing
}
else
if
(
line
.
startsWith
(
"
!
"
))
{
if
(
time
!==
"
?
"
)
{
// 已经读取完第一个禁限表的信息了,退出循环
break
;
}
else
{
time
=
line
.
substring
(
1
).
trim
();
}
}
else
{
const
cardInfo
=
parseCardInfo
(
line
);
if
(
cardInfo
)
{
forbiddens
.
set
(
cardInfo
.
cardId
,
cardInfo
.
limitCount
);
}
}
}
return
{
time
,
forbiddens
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment