mazipan / tanyaaja.in

❓Kumpulkan pertanyaan secara anonim dari siapa saja dengan mudah
https://tanyaaja.in
MIT License
134 stars 36 forks source link

FEAT: Count notion database rows #121

Closed haruelrovix closed 11 months ago

haruelrovix commented 11 months ago

Half-Closes (https://github.com/mazipan/tanyaaja/issues/88)

Description

There is no out of the box that Notion provided to get the Database count. The closest endpoint to get the Rows count is Query a Database. This is not optimal since we need to do a loop, but I cannot find any other solution. So if it's accepted, in the future we need to implement a Cache.

GET {{base_url}}/api/statistics

{
    "message": "Public statistics",
    "data": {
        "usersCount": 128
    }
}
vercel[bot] commented 11 months ago

Someone is attempting to deploy a commit to a Personal Account owned by @mazipan on Vercel.

@mazipan first needs to authorize it.

mazipan commented 11 months ago

Have you try to play with https://developers.notion.com/reference/retrieve-a-page-property?

I read that we can get a unique sum from the page property.

mazipan commented 11 months ago

Or how if we create a separate DB to store the count ya?

We will increment the number every user registration. If there is a gap, I will try to re-sync the number manually.

Wdyt?

vercel[bot] commented 11 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tanyaaja ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2023 7:22am
mazipan commented 11 months ago

But for MVP, it is accepted for now ya.

Let's work later for the improvement.

haruelrovix commented 11 months ago

Have you try to play with https://developers.notion.com/reference/retrieve-a-page-property?

I read that we can get a unique sum from the page property.

I tried but it didn't work even though Notion states:

Databases are pages themselves


image

TanyaAja Template is a Page while User and Questions are Database.

GET https://api.notion.com/v1/databases/:id

200 OK {
    "object": "database",
    "id": "a05e3b84-...

Using the same {{DATABASE_ID}}, it threw:

GET https://api.notion.com/v1/pages/:id

404 Not Found {
    "object": "error",
    "status": 404,
    "code": "object_not_found",
    "message": "Could not find page with ID: a05e3b84-...