Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

Should I use filter() instead of search()

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
performance
2 Vastaukset
12478 Näkymät
Avatar
Francesco Ballerini

EDIT --> Probably I should have print the return of model.filtered(function) before asking because I discovered that if you don't make a search() before filtered you just get the model object in return, not a recordset. So basically you have to search/browse first, no matter what. 


I still wonder if it's better to get subrecords with a second search or filtered function. 

I think we should absolutely avoid to use search() or filtered() in loops, but I see that search() seems to be more efficient for a little number of iterations, while filtered seems to be slightly better for a large number.. might that be a reason to prefer filtered over search? 

___________________________________________________________________________________________________

Hello everyone, I'm testing performance for my project and I'm trying to figure out cases when i should use search() instead of filtered(). 


I ask because of 2 reasons:  

1) I did some tests and I can see that generally self.env['model.name'].filtered()  is much faster than  self.env['model.name'].search([])


For example, 


variable = self.env['model.name'].search([('name', '=', 'value')])

is about 800 microseconds for me, EVEN IF i already istantiated model or recordset with another search and perform search() on the model or recordset (in the latter case is like 600 microseconds but still worse than filtered)


When


variable = self.env['model.name'].filtered(lambda r: r.name == name) 

is about 250 microseconds.

And if I try to iterate n times the instructions, the results are basically the same.


2) BUT i also see that in Odoo source code, models recordsets are firstly fetched by using search() or browse() , and only then the results are filtered.


Now, from what I understand, one problem of filtered() might be that if I need to fetch the full recordset of a model to be able loop through it, I probably need to use search (or maybe browse) because I don't think there is a way to get the full recordset out the filtered method.


But in other situations, where I just need to fetch a subrecordset or even a single record, why not directly use filtered if it's faster instead of make a search() and then filter it later? Can some one explain? I find very poor explanations about it. Thanks! 


0
Avatar
Hylkää
Francesco Ballerini
Tekijä

Thanks Cybrosys, so basically with search() you're fetching from database while filtered() doesn't make a query. Interesting.

By the way, your tutorials are very helpful!

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Paras vastaus

Hi.

As you said .filtered() is faster than .search()
.filtered() is used for an object of a record that can be specific.That is we are filtered out of a record from a record set.
But .search() is used for the whole model records. That is searching a record from a database table.
In general, you usually use a .search for doing database queries and getting specific results from the database. You'll use filtered() mostly when you want to filter out a part of a record set in the Python code without doing database operations anymore.

Regards

1
Avatar
Hylkää
Hariom Pandya

I was also having same doubt but able to locate this question.
Awesome question and to-the-point answer by cybrosys.
Thank you Francesco Ballerini and Cybrosys.

Avatar
Indira
Paras vastaus

Muchas gracias a todos, tenía esta misma duda y he podido aclararla, 

Saludos desde Cuba

0
Avatar
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
What is the role of Social User and Social Manager in Social Marketing Module. Ratkaistu
performance
Avatar
Avatar
2
marrask. 25
676
I'm Looking for a real estate Web Design and Development Agency in Dubai
performance
Avatar
Avatar
Avatar
Avatar
Avatar
4
syysk. 25
2003
work orders duration
performance
Avatar
0
heinäk. 25
1716
Slow Download Speed with Custom Odoo Module
performance
Avatar
0
helmik. 25
2572
Odoo - Memcached - Postgresql
performance
Avatar
0
toukok. 21
10794
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now