italia / verificac19-sdk

✅ Official VerificaC19 Node.js SDK
MIT License
49 stars 17 forks source link

MongoDB takes too long to delete old revoked uvci #24

Closed anversoft closed 2 years ago

anversoft commented 2 years ago

When the revoked certificates are too many (> 50000) MongoDB takes too long to delete the certificates (+ 2h), I found it more efficient to completely delete the database and download the new certificates instead of deleting them one by one, the clean up threshold can be set using the env variable VC19_MONGODB_CLEAN_THRESHOLD (default 50000).

astagi commented 2 years ago

Ciao @anversoft,

thank you for this PR, great catch! I think that a better and most efficient solution could be using deleteMany to delete entries, something like

this._dbModel.deleteMany({ id: { $in: deletedRevokedUvci }})

Try and let me know, in case could you please rewrite that part using deleteMany?

codecov[bot] commented 2 years ago

Codecov Report

Merging #24 (71c4773) into master (55a43bd) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #24   +/-   ##
=======================================
  Coverage   97.98%   97.98%           
=======================================
  Files           8        8           
  Lines         398      398           
=======================================
  Hits          390      390           
  Misses          8        8           
Impacted Files Coverage Δ
src/service.js 95.77% <ø> (ø)
src/cache.js 100.00% <100.00%> (ø)
src/crl.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 55a43bd...71c4773. Read the comment docs.

anversoft commented 2 years ago

Ok, i tried a few times and now it works fine. I removed the env variable VC19_MONGODB_CLEAN_THRESHOLDbecause with deleteManyit is no longer necessary but I added the env variable VC19_UPDATE_HOURSto force the check of the clr since the revoked certificates are updated every 5/6 hours

astagi commented 2 years ago

Great @anversoft ! Thank you so much!