Postlar filtri






JavaHere's Blogs 😎 dan repost
Alhamdulillah

Bir narsalar boshlandi, ohiri xayrli bo'lsin)

Background checking qismi qoldi




My Engineering Space | Cracking MAANG 🪐 dan repost
#swe

Concurrency and Parallelism








https://www.linkedin.com/posts/ykdojo_from-the-limited-information-ive-been-able-activity-7173670892265299969-w1A_?utm_source=share&utm_medium=member_android
YK Sugi on LinkedIn: From the limited information I’ve been able to gather, Devin from…
From the limited information I’ve been able to gather, Devin from Cognition Labs (what they call an AI software engineer) works well. It doesn’t seem like a…


Webhook
Bir software system ikkinchi system'ga o'zgarish(event) haqida message yuborish uchun webhook ishlatilishi mumkin. Misol uchun do'konga chiqdik non olgani, lekin do'konda yo'q ekan, sotuvchi qachon yetkazilsa o'zim xabar beraman dedi. Webhook polling'dan farqli ravishda event bo'lsa xabar beradi.




Resetting PK sequence in table
PK odatda id bo'ladi table'da, PK'ni manual set qilib insert qilsak, PK seqeunce o'zgarmaydi.

[5] pry(main)> Friend.maximum(:id)
(2.1ms) SELECT MAX("friends"."id") FROM "friends"
=> 2
[6] pry(main)> ActiveRecord::Base.connection.exec_query("select last_value from friends_id_seq").as_json
SQL (0.9ms) select last_value from friends_id_seq
=> [{"last_value"=>1}]

Agar PK sequence'ni reset qilmay table'ga insert qiladigan bo'lsak validation'dan o'tmaydi:

Friend.create(name: 'c')
DETAIL: Key (id)=(1) already exists.

PK sequence'ni reset qilish uchun console'da run qilishimiz kerak:

ActiveRecord::Base.connection.reset_pk_sequence!('friends')

yoki

SELECT setval('friends_id_seq', COALESCE((SELECT MAX(id)+1 FROM friends), 1), false)




Associated recordlarni olish uchun Ruby on Railsda bir nechta usullar bor:

1. preload
2. includes
3. eager_load

1. Preload
N+1 query problemni hal qiladi, associated datani xotirada vaqtincha saqlaydi. Load qilishda 2 ta alohida query bajaradi.

Message.preload(:user).all each do |mes|
puts message.user.email
end

Message Load (2.2ms) SELECT "messages".* FROM "messages"
User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."id" IN ($1, $2, $3) [["id", 2], ["id", 1], ["id", 4]]

Bu esa associated datani filter qilishga yo'l qo'ymaydi.

Message.preload(:user).where(users: { id: [1, 2, 3] }) results in an error

2. Includes ham associated datani load qiladi xotirada.

Message.includes(:user)

Message Load (2.2ms) SELECT "messages".* FROM "messages"
User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."id" IN ($1, $2, $3) [["id", 2], ["id", 1], ["id", 4]]

Ko'rganingizdek query preloaddek bir xil. Lekin includes preloaddan farqli ravishda filter qilishga imkon beradi:

User.includes(:messages).where(messages: { chat_room_id: [1, 2, 3] })

SQL (3.9ms) SELECT "users"."id" AS t0_r0, "users"."email" AS t0_r1, "messages"."id" AS t1_r0, "messages"."content" AS t1_r1, "messages"."user_id" AS t1_r2 LEFT OUTER JOIN "messages" ON "messages"."user_id" = "users"."id" WHERE "messages"."chat_room_id" IN ($1, $2, $3) [["chat_room_id", 1], ["chat_room_id", 2], ["chat_room_id", 3]]

Demak includes filter qilmasak preloaddek ishlaydi, filter qilsak Left Join ishlatadi.

3. eager_load ham N+1 query problemni hal qiladi. U har doim Left Join ishlatadi (doimo 1 ta queryda load qiladi))


N+1 query problem ma'lum bo'lgan recordlar uchun associated table'ni data'sini olishga query yuborishdan kelib chiqadi. Bu muammo'ga sample yuqorida keltirilgan.

Solution.

Eagerloading
eagerloading har bir message uchun userni load qilib oladi va xotirada vaqtincha saqlaydi. message.user.email har safar users table'ga borishi shart bo'lmaydi.
Message Load (2.2ms) SELECT "messages".* FROM "messages"
User Load (1.7ms) SELECT "users".* FROM "users" WHERE "users"."id" IN ($1, $2, $3) [["id", 2], ["id", 1], ["id", 4]]


bizda Users va Messages table'lar bor, User has_many Messages;

User'lar soni 5 ta, har bir userda 3 tadan message bor.

Message.each do |message|
print message.user.email
end

bu yerda nechta query bajariladi?


git diff with 3 dots compares the latest commit on your feature branch with that common ancestor commit, which is essentially the point from where you branched off to create your feature.


boshlangan commitdan oxirgi commitgacha farqlarni chiqaradi


authentication va authorization farqi nimada?


#TechTalks 2-soni

Eslatib o'tmoqchiman, ushbu podcastda xatoliklar bo'lgan bo'lishi mumkin.
Nothing is perfect

deganlaridek podcast yoki talk qilishda yangimiz, aybga buyurmaysiz deb umid qilaman.

Ushbu podcastda asosan Database Internals mavzusida boshlang'ich tushunchalar haqida gap ketgan. Umid qilaman kelasi sonlarda yana ham chuqurroq va yaxshiroq qilishga harakat qilamiz.

Mehmon: Bobosher Musurmonov

Keyingi sonida nima haqida va kimni taklif qilishimizni istaysiz, izohlarda yozing.

@otabekswe


index'larni qaysi hollarda ishlatishimiz kerak ekan? leave comments below

20 ta oxirgi post ko‘rsatilgan.

13

obunachilar
Kanal statistikasi