pvorb / npm-stat.com

download statistics for npm packages
https://npm-stat.com/
Apache License 2.0
1.16k stars 50 forks source link

SQL error when requesting stats by author #64

Open steelbrain opened 6 years ago

steelbrain commented 6 years ago

URL: https://npm-stat.com/charts.html?author=steelbrain&from=2015-07-15&to=2018-07-14

JSON response: https://gist.github.com/steelbrain/fd9d27b7c0a515a23d479f0d9551d023

How it was rendered in the browser:

pvorb commented 6 years ago

I couldn't reproduce the issue, but I've updated the service since you opened this issue, so I guess it's fixed now.

Could you please confirm this is no longer an issue?

johnbrett commented 6 years ago

I recently tried a search and got this error, but then searched again and it didn't happen. Not sure if that'll help with debugging :/

pvorb commented 6 years ago

Well, could you be a little more precise what you mean with "recently"?

johnbrett commented 6 years ago

Oh apologies :) I'd meant like 30 minutes before I posted the comment.

kumavis commented 5 years ago

@pvorb I get the same ERROR: duplicate key value for https://npm-stat.com/charts.html?author=kumavis

MoOx commented 5 years ago

I just faced this issue. Then I waited a little, & then, while trying again after having prepared an issue & trying to double check the problem, issue was gone!

marvinhagemeister commented 4 years ago

Just ran into the same error when checking the stats for my username.

URL to reproduce: https://npm-stat.com/charts.html?author=marvinhagemeister&from=2019-07-05&to=2020-07-05

pvorb commented 4 years ago

@marvinhagemeister It takes a while but it works without a problem for me. Can you please try again?

marvinhagemeister commented 4 years ago

@pvorb Weird, you're right it works now. Not sure what changed :shrug:

pvorb commented 4 years ago

I know that npm returned 500 errors today, so probably this was the cause.

steelbrain commented 4 years ago

Guess from personal experience: When you request the stats once, even if you abort the network connection, the request continues, so if you make a subsequent request you get this error.

Fix is to just wait for the first request to finish, after it finishes, the results are cached. So you can request again and it'll respond from cache and it'll work fine.

willin commented 2 years ago
Could not fetch data. 500 error {"timestamp":"2021-11-24T07:40:18.685+0000","status":500,"error":"Internal Server Error","message":"jOOQ; SQL [insert into \"public\".\"download_count\" (\"package_name\", \"date\", \"count\") values (?, cast(? as date), ?)]; ERROR: duplicate key value violates unique constraint \"72_72_download_count_pkey\"\n Detail: Key (package_name, date)=(@white-matrix/blindbox-sdk, 2020-11-23) already exists.; nested exception is org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint \"72_72_download_count_pkey\"\n Detail: Key (package_name, date)=(@white-matrix/blindbox-sdk, 2020-11-23) already exists.","path":"/npm-stat/api/download-counts"}

https://npm-stat.com/charts.html?author=willin

pvorb commented 2 years ago

Yep, that's the same problem. The transaction fails because of two concurrent writes. I could add a retry mechanism, but I think this problem is quite rare and fixed by reloading the site.