npm-stat.com icon indicating copy to clipboard operation
npm-stat.com copied to clipboard

SQL error when requesting stats by author

Open steelbrain opened this issue 6 years ago • 13 comments

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:

steelbrain avatar Jul 15 '18 10:07 steelbrain

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?

pvorb avatar Jul 24 '18 22:07 pvorb

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 :/

johnbrett avatar Aug 01 '18 13:08 johnbrett

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

pvorb avatar Aug 01 '18 17:08 pvorb

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

johnbrett avatar Aug 02 '18 09:08 johnbrett

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

kumavis avatar Feb 28 '19 01:02 kumavis

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!

MoOx avatar May 22 '19 21:05 MoOx

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

marvinhagemeister avatar Jul 06 '20 15:07 marvinhagemeister

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

pvorb avatar Jul 06 '20 17:07 pvorb

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

marvinhagemeister avatar Jul 06 '20 18:07 marvinhagemeister

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

pvorb avatar Jul 06 '20 19:07 pvorb

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.

steelbrain avatar Jul 06 '20 19:07 steelbrain

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

willin avatar Nov 24 '21 07:11 willin

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.

pvorb avatar Nov 24 '21 19:11 pvorb