Skip to content

Commit

Permalink
Defer db load (#79)
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu authored Dec 14, 2023
1 parent b20232e commit c43479c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "appthreat-vulnerability-db"
version = "5.5.5"
version = "5.5.6"
description = "AppThreat's vulnerability database and package search library with a built-in file based storage. OSV, CVE, GitHub, npm are the primary sources of vulnerabilities."
authors = [
{name = "Team AppThreat", email = "[email protected]"},
Expand Down
10 changes: 6 additions & 4 deletions vdb/lib/nvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
now = datetime.datetime.now()
# Size of the stream to read and write to the file
download_chunk_size = 128
# Create database
db = dbLib.get()

json_lib = orjson if ORJSON_AVAILABLE else json

Expand All @@ -57,6 +55,8 @@ class NvdSource(VulnerabilitySource):

def download_all(self, local_store=True):
"""Download all historic cve data"""
# Create database
self.db = dbLib.get()
data_list = []
for y in range(now.year, int(start_year) - 1, -1):
data = self.fetch(y)
Expand All @@ -68,6 +68,8 @@ def download_all(self, local_store=True):

def download_recent(self, local_store=True):
"""Method which downloads the recent CVE gzip from NVD"""
# Create database
self.db = dbLib.get()
data = self.fetch("recent")
if local_store:
self.store(data)
Expand Down Expand Up @@ -114,10 +116,10 @@ def refresh(self):

def store(self, data, reindex=True):
"""Store data in the database"""
docs = dbLib.store(db, data, reindex)
docs = dbLib.store(self.db, data, reindex)

This comment has been minimized.

Copy link
@prabhu

prabhu Jan 24, 2024

Author Contributor

This has created a bug in situations where download_all doesn't get invoked.

return docs

def bulk_search():
def bulk_search(self):
"""
Bulk search the resource instead of downloading the information
:return: Vulnerability result
Expand Down

0 comments on commit c43479c

Please sign in to comment.