You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

package_access_stat.go 2.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package db
  2. /*
  3. import (
  4. "github.com/jmoiron/sqlx"
  5. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  6. stgmod "gitlink.org.cn/cloudream/storage/common/models"
  7. coormq "gitlink.org.cn/cloudream/storage/common/pkgs/mq/coordinator"
  8. )
  9. type PackageAccessStatDB struct {
  10. *DB
  11. }
  12. func (db *DB) PackageAccessStat() *PackageAccessStatDB {
  13. return &PackageAccessStatDB{db}
  14. }
  15. func (*PackageAccessStatDB) Get(ctx SQLContext, pkgID cdssdk.PackageID, hubID cdssdk.HubID) (stgmod.PackageAccessStat, error) {
  16. var ret stgmod.PackageAccessStat
  17. err := sqlx.Get(ctx, &ret, "select * from PackageAccessStat where PackageID=? and HubID=?", pkgID, hubID)
  18. return ret, err
  19. }
  20. func (*PackageAccessStatDB) GetByPackageID(ctx SQLContext, pkgID cdssdk.PackageID) ([]stgmod.PackageAccessStat, error) {
  21. var ret []stgmod.PackageAccessStat
  22. err := sqlx.Select(ctx, &ret, "select * from PackageAccessStat where PackageID=?", pkgID)
  23. return ret, err
  24. }
  25. func (*PackageAccessStatDB) BatchGetByPackageID(ctx SQLContext, pkgIDs []cdssdk.PackageID) ([]stgmod.PackageAccessStat, error) {
  26. if len(pkgIDs) == 0 {
  27. return nil, nil
  28. }
  29. var ret []stgmod.PackageAccessStat
  30. stmt, args, err := sqlx.In("select * from PackageAccessStat where PackageID in (?)", pkgIDs)
  31. if err != nil {
  32. return nil, err
  33. }
  34. err = sqlx.Select(ctx, &ret, stmt, args...)
  35. return ret, err
  36. }
  37. func (*PackageAccessStatDB) BatchAddCounter(ctx SQLContext, entries []coormq.AddAccessStatEntry) error {
  38. if len(entries) == 0 {
  39. return nil
  40. }
  41. sql := "insert into PackageAccessStat(PackageID, HubID, Counter, Amount)" +
  42. " values(:PackageID, :HubID, :Counter, 0) as new" +
  43. " on duplicate key update Counter=Counter+new.Counter"
  44. err := BatchNamedExec(ctx, sql, 4, entries, nil)
  45. return err
  46. }
  47. func (*PackageAccessStatDB) BatchUpdateAmount(ctx SQLContext, pkgIDs []cdssdk.PackageID, historyWeight float64) error {
  48. if len(pkgIDs) == 0 {
  49. return nil
  50. }
  51. stmt, args, err := sqlx.In("update PackageAccessStat set Amount=Amount*?+Counter*(1-?), Counter = 0 where PackageID in (?)", historyWeight, historyWeight, pkgIDs)
  52. if err != nil {
  53. return err
  54. }
  55. _, err = ctx.Exec(stmt, args...)
  56. return err
  57. }
  58. func (*PackageAccessStatDB) UpdateAllAmount(ctx SQLContext, historyWeight float64) error {
  59. stmt, args, err := sqlx.In("update PackageAccessStat set Amount=Amount*?+Counter*(1-?), Counter = 0", historyWeight, historyWeight)
  60. if err != nil {
  61. return err
  62. }
  63. _, err = ctx.Exec(stmt, args...)
  64. return err
  65. }
  66. func (*PackageAccessStatDB) DeleteByPackageID(ctx SQLContext, pkgID cdssdk.PackageID) error {
  67. _, err := ctx.Exec("delete from PackageAccessStat where PackageID=?", pkgID)
  68. return err
  69. }
  70. */

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。