diff --git a/app/models/gitea/public_key.rb b/app/models/gitea/public_key.rb index bb219235..2ce09052 100644 --- a/app/models/gitea/public_key.rb +++ b/app/models/gitea/public_key.rb @@ -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 diff --git a/app/models/gitea/webhook.rb b/app/models/gitea/webhook.rb index f60f5678..77aa3c7d 100644 --- a/app/models/gitea/webhook.rb +++ b/app/models/gitea/webhook.rb @@ -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 \ No newline at end of file +end diff --git a/app/models/gitea/webhook_task.rb b/app/models/gitea/webhook_task.rb index d19a163a..21f42c6a 100644 --- a/app/models/gitea/webhook_task.rb +++ b/app/models/gitea/webhook_task.rb @@ -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 \ No newline at end of file +end diff --git a/app/models/statistic.rb b/app/models/statistic.rb new file mode 100644 index 00000000..4785060f --- /dev/null +++ b/app/models/statistic.rb @@ -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 diff --git a/config/schedule.rb b/config/schedule.rb index 1c05b516..6833ca1a 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -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 diff --git a/db/migrate/20211207012816_create_statistics.rb b/db/migrate/20211207012816_create_statistics.rb new file mode 100644 index 00000000..a0af01ee --- /dev/null +++ b/db/migrate/20211207012816_create_statistics.rb @@ -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 diff --git a/spec/models/statistic_spec.rb b/spec/models/statistic_spec.rb new file mode 100644 index 00000000..ba27a8f2 --- /dev/null +++ b/spec/models/statistic_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Statistic, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end