Compare commits

...

2 Commits

Author SHA1 Message Date
qyzh 6571db8a3c sponsor config 2021-12-07 16:20:42 +08:00
qyzh 2a02b6f530 每日统计 2021-12-07 09:45:33 +08:00
8 changed files with 125 additions and 2 deletions

View File

@ -1,3 +1,24 @@
# == Schema Information
#
# Table name: public_key
#
# id :integer not null, primary key
# owner_id :integer not null
# name :string(255) not null
# fingerprint :string(255) not null
# content :text(65535) not null
# mode :integer default("2"), not null
# type :integer default("1"), not null
# login_source_id :integer default("0"), not null
# created_unix :integer
# updated_unix :integer
#
# Indexes
#
# IDX_public_key_fingerprint (fingerprint)
# IDX_public_key_owner_id (owner_id)
#
class Gitea::PublicKey < Gitea::Base
self.inheritance_column = nil # FIX The single-table inheritance mechanism failed
# establish_connection :gitea_db

View File

@ -1,3 +1,34 @@
# == Schema Information
#
# Table name: webhook
#
# id :integer not null, primary key
# repo_id :integer
# org_id :integer
# url :text(65535)
# signature :text(65535)
# http_method :string(255)
# content_type :integer
# secret :text(65535)
# events :text(65535)
# is_ssl :boolean
# is_active :boolean
# hook_task_type :integer
# meta :text(65535)
# last_status :integer
# created_unix :integer
# updated_unix :integer
# is_system_webhook :boolean default("0"), not null
#
# Indexes
#
# IDX_webhook_created_unix (created_unix)
# IDX_webhook_is_active (is_active)
# IDX_webhook_org_id (org_id)
# IDX_webhook_repo_id (repo_id)
# IDX_webhook_updated_unix (updated_unix)
#
class Gitea::Webhook < Gitea::Base
serialize :events, JSON
self.inheritance_column = nil
@ -10,4 +41,4 @@ class Gitea::Webhook < Gitea::Base
enum hook_task_type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9}
enum last_status: {waiting: 0, succeed: 1, fail: 2}
enum content_type: {json: 1, form: 2}
end
end

View File

@ -1,3 +1,30 @@
# == Schema Information
#
# Table name: hook_task
#
# id :integer not null, primary key
# repo_id :integer
# hook_id :integer
# uuid :string(255)
# type :integer
# url :text(65535)
# signature :text(65535)
# payload_content :text(65535)
# http_method :string(255)
# content_type :integer
# event_type :string(255)
# is_ssl :boolean
# is_delivered :boolean
# delivered :integer
# is_succeed :boolean
# request_content :text(65535)
# response_content :text(65535)
#
# Indexes
#
# IDX_hook_task_repo_id (repo_id)
#
class Gitea::WebhookTask < Gitea::Base
serialize :payload_content, JSON
serialize :request_content, JSON
@ -10,4 +37,4 @@ class Gitea::WebhookTask < Gitea::Base
belongs_to :webhook, class_name: "Gitea::Webhook", foreign_key: :hook_id
enum type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9}
end
end

24
app/models/statistic.rb Normal file
View File

@ -0,0 +1,24 @@
# == Schema Information
#
# Table name: statistics
#
# id :integer not null, primary key
# dau :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class Statistic < ApplicationRecord
def self.record
users = User.all
count = 0
t = Time.now - 1.day
# t = Time.now.at_beginning_of_day
users.each do |u|
if !u.last_login_on.nil? && u.last_login_on >= t
count += 1
end
end
Statistic.create(dau: count)
end
end

View File

@ -799,6 +799,9 @@ class User < Owner
end
def daily_reward
if !Rails.application.config_for(:configuration)["sponsor"]
return
end
t1 = Time.now
t2 = Time.new(t1.year, t1.month, t1.day)

View File

@ -23,6 +23,9 @@ set :environment, :development
every '0 1 20 * *' do
runner 'Sponsorship.monthly_payment'
end
every '0 2 * * *' do
runner 'Statistic.record'
end
# every 1.month, at: 'January 20th 10:00am' do
# runner 'Sponsorship.monthly_payment'
# end

View File

@ -0,0 +1,9 @@
class CreateStatistics < ActiveRecord::Migration[5.2]
def change
create_table :statistics do |t|
t.integer :dau
t.timestamps
end
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Statistic, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end