Skip to content

Commit 47d6661

Browse files
committed
Fix for reference tables having more than 100 entries
1 parent a6be9c3 commit 47d6661

1 file changed

Lines changed: 30 additions & 33 deletions

File tree

src/data.js

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,49 @@ const core = require('@actions/core')
33
const loadData = async ({ notion }) => {
44
const systemDb = core.getInput('system_database')
55
const ownerDb = core.getInput('owner_database')
6-
const database = core.getInput('database')
6+
const serviceDb = core.getInput('database')
77

8-
const processRows = (data) => {
9-
const parent = {}
10-
data.results.forEach((row) => {
11-
const name = row.properties.Name?.title[0]?.plain_text?.toLowerCase()
12-
if (name) parent[name] = row.id
13-
})
14-
return parent
8+
const getDatabaseRows = async (databaseId, rowFunction, startCursor) => {
9+
try {
10+
const pageRows = await notion.databases.query({
11+
database_id: databaseId,
12+
start_cursor: startCursor
13+
})
14+
pageRows.results.forEach(rowFunction)
15+
if (pageRows.has_more) {
16+
return await getDatabaseRows(databaseId, rowFunction, pageRows.next_cursor)
17+
}
18+
} catch (ex) {
19+
error = true
20+
core.error(`Failed to retrieve data: ${ex.message}`)
21+
}
1522
}
1623

1724
// Get core DB structure
1825
const dbStructure = await notion.databases.retrieve({
19-
database_id: database
26+
database_id: serviceDb
2027
})
2128
const structure = Object.keys(dbStructure.properties).map((property) => {
2229
return { name: dbStructure.properties[property].name, type: dbStructure.properties[property].type }
2330
})
2431

2532
// Get the system and owner db
26-
let systemRows, ownerRows
27-
33+
const systems = {}
2834
if (systemDb) {
29-
systemRows = await notion.databases.query({
30-
database_id: systemDb
35+
await getDatabaseRows(systemDb, (row) => {
36+
const name = row.properties.Name?.title[0]?.plain_text?.toLowerCase()
37+
if (name) systems[name] = row.id
3138
})
3239
}
3340

41+
const owners = {}
3442
if (ownerDb) {
35-
ownerRows = await notion.databases.query({
36-
database_id: ownerDb
43+
await getDatabaseRows(ownerDb, (row) => {
44+
const name = row.properties.Name?.title[0]?.plain_text?.toLowerCase()
45+
if (name) owners[name] = row.id
3746
})
3847
}
3948

40-
const systems = processRows(systemRows) || null
41-
const owners = processRows(ownerRows) || null
4249
let error = false
4350

4451
if (ownerDb && !owners.unknown) {
@@ -52,22 +59,12 @@ const loadData = async ({ notion }) => {
5259

5360
// Get the current service matrix and hashes in bulk to speed up updates
5461
const services = {}
55-
const getDatabaseRows = async (startCursor) => {
56-
const pageRows = await notion.databases.query({
57-
database_id: database,
58-
start_cursor: startCursor
59-
})
60-
pageRows.results.forEach((item) => {
61-
const pageId = item.id
62-
const pageHash = item.properties?.Hash?.rich_text[0]?.text?.content
63-
const pageName = item.properties?.Name?.title[0]?.text?.content
64-
services[pageName] = { pageId, pageHash }
65-
})
66-
if (pageRows.has_more) {
67-
return await getDatabaseRows(pageRows.next_cursor)
68-
}
69-
}
70-
await getDatabaseRows()
62+
await getDatabaseRows(serviceDb, (item) => {
63+
const pageId = item.id
64+
const pageHash = item.properties?.Hash?.rich_text[0]?.text?.content
65+
const pageName = item.properties?.Name?.title[0]?.text?.content
66+
services[pageName] = { pageId, pageHash }
67+
})
7168

7269
if (error) {
7370
process.exit(1)

0 commit comments

Comments
 (0)