How to use find_or_create_by method of Sort Package

Best Active_mocker_ruby code snippet using Sort.find_or_create_by

cache_update.rake

Source:cache_update.rake Github

copy

Full Screen

...9 # result10 # }.reverse11 # end12 #global_topic_calculations13 $topics = Topic.nondeleted.where(:asks_count.gt=>SettingItem.find_or_create_by(:key=>"hot_topics_asks_count").value.to_i,:followed_count.gt=>SettingItem.find_or_create_by(:key=>"hot_topics_followers_count").value.to_i).to_a.collect{|x| [x.name,x.followers_count,(last_ask=AskLog.where(:action=>'ADD_TOPIC').where(:title=>x.name).last).blank? ? 0 : last_ask.created_at,(last_follow=UserLog.where(:action=>'FOLLOW_TOPIC').where(:target_parent_title=>x.name).last).blank? ? 0 : last_follow.created_at]}14 if SettingItem.find_or_create_by(:key=>"hot_topics_sort_by").value.to_s=="last_followed_at"15 $topics =$topics.sort{|x,y|y[3].to_i<=>x[3].to_i}16 else17 $topics =$topics.sort{|x,y|y[2].to_i<=>x[2].to_i}18 end19 #AnswerLog.where(action:'NEW').where(:created_at.gt=>150.days.ago).where(target_parent_id:x.id).count20 $asks = Ask.normal.nondeleted.where(:created_at.gt=>SettingItem.find_or_create_by(:key=>"hot_asks_created_at").value.to_i.days.ago,:answers_count.gte=>SettingItem.find_or_create_by(:key=>"hot_asks_answers_count").value.to_i).to_a.collect{|x| [x,x.last_answer.blank? ? 0 : x.last_answer.created_at]}21 if SettingItem.find_or_create_by(:key=>"hot_asks_sort_by").value.to_s=="answers_count"22 $asks =$asks.sort{|x,y|y[0].answers_count.to_i<=>x[0].answers_count.to_i}23 else24 $asks =$asks.sort{|x,y|y[1].to_i<=>x[1].to_i}25 end26 27 # TopicCache.delete_all28 Mongoid.database.collection('topic_caches').drop29 $topics.each_with_index do |topic,i|30 TopicCache.create!(name:topic[0],hot_rank:i,followers_count:topic[1])31 end32 # AskCache.delete_all33 Mongoid.database.collection('ask_caches').drop34 $asks.each_with_index do |a,i|35 ask=a[0]36 AskCache.create!(ask_id:ask.id,hot_rank:i)37 end 38 39 # ExpertCache.delete_all40 Mongoid.database.collection('expert_caches').drop41 User.where(:is_expert=>true).collect(&:tags).flatten.uniq.each do |tag|42 ec = ExpertCache.create!(tag:tag)43 @ask_ids = Ask.where(:topics => tag).normal.collect(&:id)44 ec.experts = User.where(:is_expert=>true).where(:tags=>tag).to_a.sort{|x,y| x.answers.any_in(:ask_id=>@ask_ids).count <=> y.answers.any_in(:ask_id=>@ask_ids).count}.reverse.collect(&:id)45 ec.save!46 end47 end48 task :ask_cache => :environment do49 $asks = Ask.normal.nondeleted.where(:created_at.gt=>SettingItem.find_or_create_by(:key=>"hot_asks_created_at").value.to_i.days.ago,:answers_count.gte=>SettingItem.find_or_create_by(:key=>"hot_asks_answers_count").value.to_i).to_a.collect{|x| [x,x.last_answer.blank? ? 0 : x.last_answer.created_at]}50 if SettingItem.find_or_create_by(:key=>"hot_asks_sort_by").value.to_s=="answers_count"51 $asks =$asks.sort{|x,y|y[0].answers_count.to_i<=>x[0].answers_count.to_i}52 else53 $asks =$asks.sort{|x,y|y[1].to_i<=>x[1].to_i}54 end55 56 # AskCache.delete_all57 Mongoid.database.collection('ask_caches').drop58 $asks.each_with_index do |a,i|59 ask=a[0]60 AskCache.create!(ask_id:ask.id,hot_rank:i)61 end62 end63 task :topic_cache => :environment do64 $topics = Topic.nondeleted.where(:asks_count.gt=>SettingItem.find_or_create_by(:key=>"hot_topics_asks_count").value.to_i,:followed_count.gt=>SettingItem.find_or_create_by(:key=>"hot_topics_followers_count").value.to_i).to_a.collect{|x| [x.name,x.followers_count,(last_ask=AskLog.where(:action=>'ADD_TOPIC').where(:title=>x.name).last).blank? ? 0 : last_ask.created_at,(last_follow=UserLog.where(:action=>'FOLLOW_TOPIC').where(:target_parent_title=>x.name).last).blank? ? 0 : last_follow.created_at]}65 if SettingItem.find_or_create_by(:key=>"hot_topics_sort_by").value.to_s=="last_followed_at"66 $topics =$topics.sort{|x,y|y[3].to_i<=>x[3].to_i}67 else68 $topics =$topics.sort{|x,y|y[2].to_i<=>x[2].to_i}69 end70 # TopicCache.delete_all71 Mongoid.database.collection('topic_caches').drop72 $topics.each_with_index do |topic,i|73 TopicCache.create!(name:topic[0],hot_rank:i,followers_count:topic[1])74 end75 end76 task :expert_cache => :environment do77 # ExpertCache.delete_all78 Mongoid.database.collection('expert_caches').drop79 User.where(:is_expert=>true).collect(&:tags).flatten.uniq.each do |tag|...

Full Screen

Full Screen

classification.rb

Source:classification.rb Github

copy

Full Screen

...3 has_many :videos4 enum status: { disabled: -1, enabled: 0 }5 default_scope -> {where(is_delete: 0)}6 def self.init_migration7 Classification.find_or_create_by(name:"社会",sort_live:10)8 Classification.find_or_create_by(name:"社会-国际",sort_live:11)9 Classification.find_or_create_by(name:"社会-时事",sort_live:12)10 Classification.find_or_create_by(name:"娱乐",sort_live:20)11 Classification.find_or_create_by(name:"娱乐-电影",sort_live:21)12 Classification.find_or_create_by(name:"娱乐-综艺",sort_live:22)13 Classification.find_or_create_by(name:"娱乐-音乐",sort_live:23)14 Classification.find_or_create_by(name:"娱乐-星座运势",sort_live:24)15 Classification.find_or_create_by(name:"娱乐-搞笑",sort_live:25)16 Classification.find_or_create_by(name:"娱乐-漫画",sort_live:26)17 Classification.find_or_create_by(name:"娱乐-百科常识",sort_live:27)18 Classification.find_or_create_by(name:"数码",sort_live:30)19 Classification.find_or_create_by(name:"数码-科技",sort_live:31)20 Classification.find_or_create_by(name:"汽车",sort_live:40)21 Classification.find_or_create_by(name:"时尚",sort_live:50)22 Classification.find_or_create_by(name:"时尚-美妆",sort_live:51)23 Classification.find_or_create_by(name:"时尚-情感",sort_live:52)24 Classification.find_or_create_by(name:"时尚-穿搭",sort_live:53)25 Classification.find_or_create_by(name:"美女",sort_live:60)26 Classification.find_or_create_by(name:"美女-舞蹈",sort_live:61)27 Classification.find_or_create_by(name:"美女-cos",sort_live:62)28 Classification.find_or_create_by(name:"色情",sort_live:70)29 Classification.find_or_create_by(name:"色情-AV",sort_live:70)30 Classification.find_or_create_by(name:"色情-18+",sort_live:70)31 Classification.find_or_create_by(name:"游戏",sort_live:80)32 Classification.find_or_create_by(name:"游戏-漫画",sort_live:81)33 Classification.find_or_create_by(name:"美食",sort_live:90)34 Classification.find_or_create_by(name:"美食-生活",sort_live:91)35 Classification.find_or_create_by(name:"旅游",sort_live:100)36 Classification.find_or_create_by(name:"旅游-摄影",sort_live:101)37 Classification.find_or_create_by(name:"居家",sort_live:110)38 Classification.find_or_create_by(name:"居家-宠物",sort_live:111)39 Classification.find_or_create_by(name:"居家-母婴育儿",sort_live:112)40 Classification.find_or_create_by(name:"居家-健康养生",sort_live:113)41 Classification.find_or_create_by(name:"居家-星座运势",sort_live:114)42 Classification.find_or_create_by(name:"军事",sort_live:120)43 Classification.find_or_create_by(name:"历史",sort_live:130)44 Classification.find_or_create_by(name:"历史-文化",sort_live:131)45 Classification.find_or_create_by(name:"财经",sort_live:140)46 Classification.find_or_create_by(name:"生活",sort_live:150)47 Classification.find_or_create_by(name:"生活-生活日常",sort_live:151)48 Classification.find_or_create_by(name:"生活-vlog",sort_live:152)49 end50 # 清除分类修改导致不一致问题51 def self.crean_diff52 Classification.all.each do |ca|53 $redis.del("classification_#{ca.id}_infos")54 $redis.del("classification_#{ca.id}_videos")55 end56 end57 # up_classification58 def self.up_classification59 Classification.all.each do |ca|60 $redis.sadd("classification_#{ca.id}_infos",Info.where("classification_id = ?", ca.id).ids)61 $redis.sadd("classification_#{ca.id}_videos",Video.where("classification_id = ?", ca.id).ids)62 end...

Full Screen

Full Screen

seeds.rb

Source:seeds.rb Github

copy

Full Screen

...13 password_confirmation: "password",14 name: "テスト2"15 )16end17PaymentClassification.find_or_create_by!(purpose: :required, name: "食費", sort: 1)18PaymentClassification.find_or_create_by!(purpose: :required, name: "居住費", sort: 2)19PaymentClassification.find_or_create_by!(purpose: :required, name: "水道光熱費", sort: 3)20PaymentClassification.find_or_create_by!(purpose: :required, name: "通信費", sort: 4)21PaymentClassification.find_or_create_by!(purpose: :required, name: "雑費・医療費", sort: 5)22PaymentClassification.find_or_create_by!(purpose: :required, name: "一般保険料", sort: 6)23PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "娯楽費", sort: 7)24PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "コンビニで買ったおやつ", sort: 8)25PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "本、雑誌", sort: 9)26PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "服", sort: 10)27PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "DVD", sort: 11)28PaymentClassification.find_or_create_by!(purpose: :enjoyment, name: "使途不明金", sort: 12)29PaymentMethod.find_or_create_by!(name: "現金")30PaymentMethod.find_or_create_by!(name: "ID")31PaymentMethod.find_or_create_by!(name: "クレジットカード(楽天)")32PaymentMethod.find_or_create_by!(name: "クレジットカード(SEIYU)")33PaymentMethod.find_or_create_by!(name: "クレジットカード(ヨドバシ)")34PaymentMethod.find_or_create_by!(name: "クレジットカード(VISA)")...

Full Screen

Full Screen

find_or_create_by

Using AI Code Generation

copy

Full Screen

1Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')2Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')3Sort.find_or_create_by(name: 'Java', version: '1.8.0')4Sort.find_or_create_by(name: 'Java', version: '1.8.0')5Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')6Sort.find_or_create_by(name: 'Java', version: '1.8.0')7Sort.find_or_create_by(name: 'Java', version: '1.8.0')8Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')9Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')10Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')11Sort.find_or_create_by(name: 'Java', version: '1.8.0')12Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')13Sort.find_or_create_by(name: 'Java', version: '1.8.0')14Sort.find_or_create_by(name: 'Java', version: '1.8.0')15Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')16Sort.find_or_create_by(name: 'Java', version: '1.8.0')17Sort.find_or_create_by(name: 'Java', version: '1.8.0')18Sort.find_or_create_by(name: 'Java', version: '1.8.0')19Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')20Sort.find_or_create_by(name: 'Java', version: '1.8.0')21Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')22Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')23Sort.find_or_create_by(name: 'Ruby', version: '2.0.0')24Sort.find_or_create_by(name: 'Java', version: '1.8.0')25Sort.find_or_create_by(name: 'Java', version: '1.8.0')26Sort.find_or_create_by(name: 'Ruby', version: '2.0.0

Full Screen

Full Screen

find_or_create_by

Using AI Code Generation

copy

Full Screen

1sort = Sort.find_or_create_by(name: "sort name")2sort = Sort.find_or_create_by(name: "sort name")3sort = Sort.find_or_create_by(name: "sort name")4sort = Sort.find_or_create_by(name: "sort name")5sort = Sort.find_or_create_by(name: "sort name")6sort = Sort.find_or_create_by(name: "sort name")7sort = Sort.find_or_create_by(name: "sort name")8sort = Sort.find_or_create_by(name: "sort name")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful