Skip to content

Commit

Permalink
(beta): add index for firebase indexeddb
Browse files Browse the repository at this point in the history
  • Loading branch information
tachibana-shin committed Jun 13, 2023
1 parent 9905dad commit 5d35d8b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
33 changes: 31 additions & 2 deletions firebase/firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
{
"indexes": [],
"fieldOverrides": []
"indexes": [
{
"collectionGroup": "history",
"queryScope": "COLLECTION",
"fields": [
{ "fieldPath": "timestamp", "order": "DESCENDING" }
]
},
{
"collectionGroup": "playlist",
"queryScope": "COLLECTION",
"fields": [
{ "fieldPath": "created", "order": "DESCENDING" }
]
},

{
"collectionGroup": "movies",
"queryScope": "COLLECTION",
"fields": [
{ "fieldPath": "add_at", "order": "ASCENDING" }
]
},
{
"collectionGroup": "movies",
"queryScope": "COLLECTION",
"fields": [
{ "fieldPath": "add_at", "order": "DESCENDING" }
]
}
]
}
15 changes: 15 additions & 0 deletions src/boot/firebase.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Import the functions you need from the SDKs you need
import { getAnalytics } from "@firebase/analytics"
import { initializeApp } from "@firebase/app"
import type {Index
} from "@firebase/firestore";
import {
CACHE_SIZE_UNLIMITED,
initializeFirestore,
persistentLocalCache,
persistentMultipleTabManager,
setIndexConfiguration
} from "@firebase/firestore"
import configure from "app/firebase/firestore.indexes.json"
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

Expand All @@ -32,4 +36,15 @@ const db = initializeFirestore(app, {
}),
})

setIndexConfiguration(db, configure as {
indexes: Index[]
})
// eslint-disable-next-line promise/always-return
.then(() => {
console.log("[Install indexes]: Installed indexes")
})
.catch((err) => {
console.error("[Install indexes]: failure ", err)
})

export { app, analytics, db }

0 comments on commit 5d35d8b

Please sign in to comment.