Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appbase-edge-function
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
duanjinfei
appbase-edge-function
Commits
8b7a601e
Commit
8b7a601e
authored
Dec 16, 2024
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix get app date,cache category count
parent
6bc5f6c0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
index.ts
supabase/functions/update-app-recommend/index.ts
+1
-1
index.ts
supabase/functions/update-app/index.ts
+24
-2
No files found.
supabase/functions/update-app-recommend/index.ts
View file @
8b7a601e
...
@@ -19,7 +19,7 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
...
@@ -19,7 +19,7 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
.
gt
(
'
recommend
'
,
0
)
.
gt
(
'
recommend
'
,
0
)
// .eq('is_show', 1)
// .eq('is_show', 1)
.
order
(
'
recommend
'
,
{
ascending
:
false
})
.
order
(
'
recommend
'
,
{
ascending
:
false
})
.
order
(
'
created_at
'
,
{
ascending
:
tru
e
})
// 按照创建时间排序
.
order
(
'
updated_at
'
,
{
ascending
:
fals
e
})
// 按照创建时间排序
.
range
(
offset
,
offset
+
pageSize
-
1
);
// 分页范围
.
range
(
offset
,
offset
+
pageSize
-
1
);
// 分页范围
if
(
error
)
{
if
(
error
)
{
...
...
supabase/functions/update-app/index.ts
View file @
8b7a601e
...
@@ -17,7 +17,7 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
...
@@ -17,7 +17,7 @@ async function fetchAllData(supabase, table: string, pageSize: number = 1000) {
.
select
(
'
id,name,icon,description,points,category_id,link,images,appPlatforms,caption,is_forward,is_show
'
)
// 可以根据需要调整字段
.
select
(
'
id,name,icon,description,points,category_id,link,images,appPlatforms,caption,is_forward,is_show
'
)
// 可以根据需要调整字段
.
gt
(
'
is_show
'
,
0
)
.
gt
(
'
is_show
'
,
0
)
// .eq('is_show', 1)
// .eq('is_show', 1)
.
order
(
'
created_at
'
,
{
ascending
:
tru
e
})
// 按照创建时间排序
.
order
(
'
updated_at
'
,
{
ascending
:
fals
e
})
// 按照创建时间排序
.
range
(
offset
,
offset
+
pageSize
-
1
);
// 分页范围
.
range
(
offset
,
offset
+
pageSize
-
1
);
// 分页范围
if
(
error
)
{
if
(
error
)
{
...
@@ -90,6 +90,9 @@ async function cacheAllApp(supabase) {
...
@@ -90,6 +90,9 @@ async function cacheAllApp(supabase) {
}
}
async
function
cacheCategoryApp
(
supabase
,
allApps
,
directory
,
bucketName
)
{
async
function
cacheCategoryApp
(
supabase
,
allApps
,
directory
,
bucketName
)
{
let
categoryCount
=
{
app_all
:
allApps
.
length
,
}
// 按 category_id 分组
// 按 category_id 分组
const
groupedData
:
Record
<
string
,
any
[]
>
=
{};
const
groupedData
:
Record
<
string
,
any
[]
>
=
{};
allApps
.
forEach
((
app
)
=>
{
allApps
.
forEach
((
app
)
=>
{
...
@@ -102,6 +105,7 @@ async function cacheCategoryApp(supabase, allApps, directory, bucketName) {
...
@@ -102,6 +105,7 @@ async function cacheCategoryApp(supabase, allApps, directory, bucketName) {
// 上传每个 category_id 的分页数据
// 上传每个 category_id 的分页数据
for
(
const
[
categoryId
,
apps
]
of
Object
.
entries
(
groupedData
))
{
for
(
const
[
categoryId
,
apps
]
of
Object
.
entries
(
groupedData
))
{
const
totalCount
=
apps
.
length
;
// 当前分类的总数
const
totalCount
=
apps
.
length
;
// 当前分类的总数
categoryCount
[
categoryId
]
=
totalCount
const
pageSize
=
30
;
const
pageSize
=
30
;
const
paginatedApps
=
[];
const
paginatedApps
=
[];
for
(
let
i
=
0
;
i
<
totalCount
;
i
+=
pageSize
)
{
for
(
let
i
=
0
;
i
<
totalCount
;
i
+=
pageSize
)
{
...
@@ -135,12 +139,30 @@ async function cacheCategoryApp(supabase, allApps, directory, bucketName) {
...
@@ -135,12 +139,30 @@ async function cacheCategoryApp(supabase, allApps, directory, bucketName) {
console
.
log
(
`Uploading page
${
categoryId
}
_
${
pageNum
}
.json JSON successful`
);
console
.
log
(
`Uploading page
${
categoryId
}
_
${
pageNum
}
.json JSON successful`
);
}
}
}
}
const
categoryCountFileName
=
`
${
directory
}
/category_count.json`
;
const
categoryCountJson
=
JSON
.
stringify
(
categoryCount
);
const
{
error
:
categoryCountUploadError
}
=
await
supabase
.
storage
.
from
(
bucketName
)
.
upload
(
categoryCountFileName
,
new
Blob
([
categoryCountJson
]),
{
contentType
:
'
application/json
'
,
upsert
:
true
,
});
if
(
categoryCountUploadError
)
{
console
.
error
(
`Error uploading category_count JSON:`
,
categoryCountUploadError
);
}
else
{
console
.
log
(
`Uploading page category_count JSON successful`
);
}
}
}
}
}
async
function
cacheRentUpdateApp
(
supabase
,
allApps
,
directory
,
bucketName
)
{
async
function
cacheRentUpdateApp
(
supabase
,
allApps
,
directory
,
bucketName
)
{
const
recentUpdateAppFileName
=
`
${
directory
}
/resent_update_app.json`
;
const
recentUpdateAppFileName
=
`
${
directory
}
/resent_update_app.json`
;
const
pageJson
=
JSON
.
stringify
(
allApps
.
slice
(
allApps
.
length
-
6
,
allApps
.
length
))
const
pageJson
=
JSON
.
stringify
(
allApps
.
slice
(
0
,
6
))
const
{
error
:
pageUploadError
}
=
await
supabase
.
storage
const
{
error
:
pageUploadError
}
=
await
supabase
.
storage
.
from
(
bucketName
)
.
from
(
bucketName
)
.
upload
(
recentUpdateAppFileName
,
new
Blob
([
pageJson
]),
{
.
upload
(
recentUpdateAppFileName
,
new
Blob
([
pageJson
]),
{
...
...
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