Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Leaf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Piotr Kazala CSM2020
Leaf
Commits
d5b0074c
Commit
d5b0074c
authored
1 year ago
by
Piotrek
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Fixed a major issue that was causing too many unnecessary reads from the database
parent
a61548dd
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
Fix: Multiple fixes across the app with the main being the popup now always...
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
background/index.ts
+1
-1
1 addition, 1 deletion
background/index.ts
background/messages/ping.ts
+32
-19
32 additions, 19 deletions
background/messages/ping.ts
background/messages/pingAdvanced.ts
+4
-5
4 additions, 5 deletions
background/messages/pingAdvanced.ts
with
37 additions
and
25 deletions
background/index.ts
+
1
−
1
View file @
d5b0074c
...
...
@@ -9,7 +9,7 @@ export {}
// Your web app's Firebase configuration
const
firebaseConfig
=
{
apiKey
:
"
AIzaSyAIXCufoNziwwkDEj6pF1pFs1b2ogqtITw
"
,
apiKey
:
process
.
env
.
KEY
,
authDomain
:
"
leaf-0001.firebaseapp.com
"
,
projectId
:
"
leaf-0001
"
,
storageBucket
:
"
leaf-0001.appspot.com
"
,
...
...
This diff is collapsed.
Click to expand it.
background/messages/ping.ts
+
32
−
19
View file @
d5b0074c
import
dataset
from
"
assets/dataset_small.json
"
import
{
collection
,
getDocs
,
type
DocumentData
}
from
"
firebase/firestore/lite
"
import
{
collection
,
getDocs
,
limit
,
query
,
where
,
type
DocumentData
,
}
from
"
firebase/firestore/lite
"
import
type
{
PlasmoMessaging
}
from
"
@plasmohq/messaging
"
// import initialized db instance
import
{
db
}
from
"
~background
"
// Export it!
interface
data_small
{
brand
:
string
country
:
string
environmental_total
:
number
supplychain_total
:
number
social_total
:
number
}
import
type
{
data_small
}
from
"
~interfaces/data_small
"
interface
url_data
{
name
:
string
...
...
@@ -22,11 +21,24 @@ interface url_data {
const
data
:
data_small
[]
=
dataset
async
function
queryUrls
()
{
const
urlsCollection
=
collection
(
db
,
"
urls
"
)
const
urlsSnapshot
=
await
getDocs
(
urlsCollection
)
const
urlsList
=
urlsSnapshot
.
docs
.
map
((
doc
)
=>
doc
.
data
())
return
urlsList
async
function
queryUrls
(
currentTab
:
chrome
.
tabs
.
Tab
)
{
let
answer
const
url
=
currentTab
.
url
.
split
(
"
/
"
)[
2
]
const
urlsCollection
=
query
(
collection
(
db
,
"
urls
"
),
where
(
"
url
"
,
"
==
"
,
url
),
limit
(
1
),
)
const
brandsSnapshot
=
await
getDocs
(
urlsCollection
)
if
(
brandsSnapshot
.
empty
)
{
return
answer
}
else
{
brandsSnapshot
.
forEach
((
doc
)
=>
{
answer
=
doc
.
data
()
console
.
log
(
answer
)
})
return
answer
}
}
function
ifExists
(
tokens
:
string
)
{
...
...
@@ -40,11 +52,13 @@ function getAnswers(tokens: string, validUrl: DocumentData) {
let
secondAnswer
let
mainAnswer
:
data_small
=
ifExists
(
tokens
)
// chack if mainAnswer isnt undefined and identify any brands from our dataset in the url
if
(
mainAnswer
&&
validUrl
.
name
.
toLowerCase
().
includes
(
mainAnswer
.
brand
.
toLowerCase
()))
{
if
(
mainAnswer
&&
validUrl
.
name
.
toLowerCase
().
includes
(
mainAnswer
.
brand
.
toLowerCase
())
)
{
secondAnswer
=
mainAnswer
mainAnswer
=
ifExists
(
tokens
.
replace
(
secondAnswer
.
brand
,
""
))
}
else
{
console
.
log
(
"
this must be the problem
"
)
secondAnswer
=
ifExists
(
validUrl
.
name
)
}
//make sure that if only second answer is found then it is displayed
...
...
@@ -54,10 +68,9 @@ function getAnswers(tokens: string, validUrl: DocumentData) {
const
handler
:
PlasmoMessaging
.
MessageHandler
=
async
(
req
,
res
)
=>
{
let
answer
const
urls
=
await
queryUrls
()
const
queryOptions
=
{
active
:
true
,
lastFocusedWindow
:
true
}
const
[
tab
]:
chrome
.
tabs
.
Tab
[]
=
await
chrome
.
tabs
.
query
(
queryOptions
)
const
validUrl
=
urls
.
find
((
doc
)
=>
tab
.
url
.
includes
(
doc
.
url
)
)
const
validUrl
=
await
queryUrls
(
tab
)
const
tokens
:
string
=
await
tab
.
title
if
(
validUrl
)
{
answer
=
getAnswers
(
tokens
,
validUrl
)
...
...
This diff is collapsed.
Click to expand it.
background/messages/pingAdvanced.ts
+
4
−
5
View file @
d5b0074c
...
...
@@ -4,9 +4,9 @@ import {
limit
,
query
,
where
,
type
DocumentData
type
DocumentData
,
}
from
"
firebase/firestore/lite
"
import
type
data_advanced
from
"
interfaces/data_advanced
"
import
type
{
BrandData
}
from
"
interfaces/data_advanced
"
import
type
{
PlasmoMessaging
}
from
"
@plasmohq/messaging
"
...
...
@@ -17,12 +17,11 @@ async function queryAdvancedData(brandName: string) {
const
brandsCollection
=
query
(
collection
(
db
,
"
companies
"
),
where
(
"
brand
"
,
"
==
"
,
brandName
),
limit
(
1
)
limit
(
1
)
,
)
const
brandsSnapshot
=
await
getDocs
(
brandsCollection
)
brandsSnapshot
.
forEach
((
doc
)
=>
{
brandsData
=
doc
.
data
()
console
.
log
(
brandsData
)
})
return
brandsData
}
...
...
@@ -31,7 +30,7 @@ const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
try
{
const
response
=
await
queryAdvancedData
(
req
.
body
.
name
)
res
.
send
({
response
response
,
})
}
catch
(
e
)
{
console
.
log
(
e
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment